How to create a dynamic route in react with react router

  javascript, react-router, reactjs, routes

Please am finding it difficult to create a route in react router

I want to create a route like this <Route path="/:storeId" component={StorePage} />
But I also have a route like this /stores
Any time I go to the /:storeId page it loads the /users page
Am just confuse

Here is the code

<Switch>
  <ScrollToTop>
    <MainLayout>
      <Route exact path="/">
        <Home />
      </Route>
      <Route exact path="/stores">
        <Stores />
      </Route>
      <Route exact path="/:storeId">
        <StorePage />
      </Route>
    </MainLayout>
  </ScrollToTop>
</Switch>

Any help please.

Source: Ask Javascript Questions

LEAVE A COMMENT