Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Router Dom, difference between passing id as url params or state

This is more of a poll than anything else. When working with React, do you pass parameters when routing by chaining them to the URL or as state?

Is there even a best practice to follow for this?

Params:

navigate('/edit/${user.id}')`

State:

navigate('/edit', { state : {id :user.id} } )
like image 409
Ryan Zeelie Avatar asked Oct 16 '25 03:10

Ryan Zeelie


1 Answers

For me, it depends on the action I am trying to do.

If I want a single route with some dynamic information, such as chat id, which I don't want to be stored in the URL, I prefer setting it in the history state.

But, for REST actions (edit/add and such on), I prefer chaining the id in the URL itself. It has some benefits. The primary one I see is that you can copy the URL, paste it somewhere else (different computer/browser), and you'll still access the same page with the details about the id you chained.

like image 111
r0den Avatar answered Oct 17 '25 17:10

r0den