React Router URL parameters not working

丶灬走出姿态 提交于 2019-12-06 01:44:17

When you add new routes to your app, you can't rely on hot reloading to inject the new route + components. I had to CTRL+C and run npm start again.

This solves the issue!!

Also react-router-dom is a React Router v4 package while react-router is an older version. Thanks to @HalCarleton for pointing that out. I saw code examples everywhere with react-router while the official documentation showed react-router-dom and I was really confused as to why there were two different types of packages.

Try to do somethin like this:

<Switch> <Route path="/auth/login/:token" render={props => <Login {...this.props} {...props}/>}/> <Route path="/auth/login" component={Login}/> </Switch>

First the route with the parameter and after the route without parameter. Inside my Login component I put this console.log(props.match.params.token); to test and worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!