我所在的组件的URL为
http://localhost:3000/dashboard/profile/timeline/abcd
,路线设置为
<Route path="/dashboard/profile/:screenId/:userId" component={this.Routing}/>
例如当我转到其他个人资料时
http://localhost:3000/dashboard/profile/timeline/xyz
这不是路由,但网址正在更改
任何建议都会有所帮助
答案 0 :(得分:0)
将component={this.Routing}
替换为component={Routing}
<Route exact path="/dashboard/profile/:screenId/:userId" component={Routing}/>
React : difference between <Route exact path="/" /> and <Route path="/" />
如果您的问题无法解决,请使用Switch
我也遇到这个问题,我用Switch
import {BrowserRouter, Route, Switch} from "react-router-dom";
.
.
.
.
<BrowserRouter>
<Switch>
<Route exact key="1" path="/dashboard/profile/:screenId/:userId" component={Routing}/>
</Switch>
</BrowserRouter>