Search code examples
reactjsreact-routerreact-router-redux

Route static not working


Route about-us not working. Only works when I attaching some prefix to the route Country. How can I fix it. Thanks.

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

Solution

  • Swap these 2 lines,

    Instead of:

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

    Use this:

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

    And remove the : from route country and country/:city.

    Like this:

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