路由静态不起作用

时间:2017-04-05 07:23:16

标签: reactjs react-router react-router-redux

路由about-us无效。仅在我将一些前缀附加到路由Country时才有效。我该如何解决呢?感谢。

<Route path="/" component={App}>
    <IndexRoute components={Home}/>
    <Route path=":country" components={Country}/>
    <Route path=":country/:city" components={City}/>
    <Route path="*" components={NotMatch}/>
    <Route path="about-us" components={AboutUs}/>
</Route>

2 个答案:

答案 0 :(得分:1)

交换这2行,

而不是:

<Route path="*" components={NotMatch}/>
<Route path="about-us" components={AboutUs}/>

使用此:

<Route path="about-us" components={AboutUs}/>
<Route path="*" components={NotMatch}/>

从路由:country移除country/:city

像这样:

<Route path="/" component={App}>
    <IndexRoute components={Home}/>
    <Route path="country" components={Country}/>
    <Route path="country/:city" components={City}/>
    <Route path="about-us" components={AboutUs}/>
    <Route path="*" components={NotMatch}/>
</Route>

答案 1 :(得分:0)

感谢Mayank Shukla。你给了我正确的摩擦力。

<Route path="/" component={App}>
    <IndexRoute components={Home}/>
    <Route path="/about-us" components={AboutUs}/>
    <Route path=":country" components={Country}/>
    <Route path=":country/:city" components={City}/>
    <Route path="*" components={NotMatch}/>
</Route>

这个工作。