the nested routes for reactjs and laravel have not been working

The routes are prioritised by order. So the order you have them in matters. You could do:

<Router> 
  <Switch>
    <Route exact path="/" component={Home} />
    <Route path="/blog/post/:id" component={Post} />
    <Route path="/blog" component={Blog} />
    <Route path="*" component={notfound} />
</Switch> 
</Router>

Or by using the ‘exact’ keyword like you did for the / route, so it has to be an exact match.

<Router> 
  <Switch>
    <Route exact path="/" component={Home} />
    <Route exact path="/blog" component={Blog} />
    <Route path="/blog/post/:id" component={Post} />
    <Route path="*" component={notfound} />
</Switch> 
</Router>

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top