10 examples of 'react router push' in JavaScript

Every line of 'react router push' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
51onPush(route: Route, props:{ [key: string]: any}):boolean {
52 this.refs.nav.push({...route, component:RouteIOS, passProps:{...props, route: route}});
53 return true;
54}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

28push(props, route) {
29 let routesList = this.navigator.getCurrentRoutes()
30 let nextIndex = routesList[routesList.length - 1].index + 1
31 route.props = props
32 route.index = nextIndex
33 this.navigator.push(route)
34}
19push(props, route) {
20 if(!props){
21 props = {};
22 }
23 route.props = props;
24 this.navigator.push(route);
25}
40export function push({
41 routeName,
42 params,
43 action,
44}: {
45 routeName: string;
46 params?: object;
47 action?: never;
48}): StackActionType {
49 if (action !== undefined) {
50 throw new Error(
51 'Sub-actions are not supported for `push`. Remove the `action` key from the options.'
52 );
53 }
54
55 return StackActions.push(routeName, params);
56}
56export function push(routeName: string, params?: NavigationParams) {
57 if (navigationContainer && lastNavigateTime + 500 < Date.now()) {
58 navigationContainer.dispatch(
59 StackActions.push({
60 routeName,
61 params,
62 }),
63 );
64 lastNavigateTime = Date.now();
65 }
66}
65function Router(props, context) {
66 _classCallCheck(this, Router);
67
68 _React$Component.call(this, props, context);
69
70 this.state = {
71 location: null,
72 routes: null,
73 params: null,
74 components: null
75 };
76}
9export default function Router() {
10 const [current, setCurrent] = useState('home')
11 useEffect(() => {
12 setRoute()
13 window.addEventListener('hashchange', setRoute)
14 return () => window.removeEventListener('hashchange', setRoute)
15 }, [])
16 function setRoute() {
17 const location = window.location.href.split('/')
18 const pathname = location[location.length-1]
19 console.log('pathname: ', pathname)
20 setCurrent(pathname ? pathname : 'home')
21 }
22 return (
23 <HashRouter>
24 <Nav current={current} />
25 <Switch>
26 <Route exact path='/' component={Main} />
27 <Route path='/admin' component={Admin} />
28 <Route path='/profile' component={Profile} />
29 <Route component={Main} />
30 </Switch>
31 </HashRouter>
32 )
33}
160pushRoute(route) {
161 return this.props.pushRoute(route);
162}
8export function Router({children, ...props}) {
9 assert(props.location, 'Router "location" property is missing')
10
11 const routes = useMemo(() => addRoutes(children), [])
12 return renderMatch(routes, props)
13}
41export function popToRoute(route:string, passProps:any):Action {
42 return {
43 type: POP_TO_ROUTE,
44 route,
45 passProps,
46 };
47}

Related snippets