0

I have a Route with the path "/contacts/:userIds"

                <Route
                  exact
                  path="/contacts/:usersIds"
                  component={contacts}
                />

I' having a problem where if a user is on the page /contacts/123 and then clicks on a different Link component like contacts/234 then the browser link changes but the page stays the same as the user would still be on the page /contacts/123 instead of being on /contacts/234.

Here's the code simplified, it's a map of ListItems with the Link component from "react-router-dom":

                     <ListItem
                        key={key}
                        button
                        component={Link}
                        to={
                          `/contacts/` +
                          (user1_user2)
                        }
                      >
glaze
  • 1,309
  • 2
  • 6
  • 6
  • Check this: https://stackoverflow.com/questions/43351752/react-router-changes-url-but-not-view – ysvet Sep 17 '20 at 14:35

1 Answers1

0

You can add a useEffect in your function with props.location.pathname dependency which will execute whenever there is change in URL.

  useEffect( () => {
   console.log(newUrl, props.location.pathname)
}, [props.location.pathname] )

maya_nk99
  • 502
  • 3
  • 5