反应路由器:路由不起作用

时间:2018-07-31 09:59:22

标签: javascript reactjs react-native react-router react-router-v4

我所在的组件的URL为

http://localhost:3000/dashboard/profile/timeline/abcd

,路线设置为

<Route path="/dashboard/profile/:screenId/:userId" component={this.Routing}/>

例如当我转到其他个人资料时

http://localhost:3000/dashboard/profile/timeline/xyz

这不是路由,但网址正在更改

任何建议都会有所帮助

1 个答案:

答案 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>