1

What is the purpose of passing data through parameters on the Route using react-router?

let's take an example of a chat in which on the left you have a list of chats and on the right you show the chat that the user has selected. Many website (Instagram for example) would pass the id of the chat as a parameter of the url. My question is: as you probably have the id of the chat you want to get the data from, what is the purpose of passing it as a parameter to the URL instead of just call a function that fetches the data of that chat directly?

1
  • So you can link directly to that page, and so that your browser's navigation (refresh, back, forward) actually navigate. If that information wasn't in the URL and you refreshed the page or went back, you'd have to get the user to click on the chat again, so they'd essentially lose their state on the page. Commented Jun 25, 2020 at 22:06

1 Answer 1

1

One reason is that if you reload the page you will lose in which conversation you were and instead of remaining in the same conversation you will get an error or start from "state 0", also if you want to share the URL or bookmark it to go to that exact conversation, you will need the parameter in the URL

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.