Home > Enterprise >  React - Route with pagenumber not working (Pagination)
React - Route with pagenumber not working (Pagination)

Time:07-25

I try to implement pagination. Im at my site localhost:3000/profile/ and it shows me the first 3 elements. Also the pagination itself works fine when i use for ${page} a Number liek 3 it will go to site 3. But what not working is my url:

localhost:3000/profile/page/2

moves me to and no more to and i dont know why...

<Route
    path='/profile'
    element={isLogged ? <Profile /> : <NotFound />}
    exact
/>
<Route
    path='/profile/:page'
    element={isLogged ? <Profile /> : <NotFound />}
    exact
/>

CodePudding user response:

Nested routes are required to make subroutes with params working

<Route
        path='/profile'
        element={isLogged ? <Profile /> : <NotFound />}
        exact
      >
        <Route
          path='page/:page'
          element={isLogged ? <Profile /> : <NotFound />}
          exact
        />
      </Route>
  • Related