hudson221b / nextmatch

https://next-match-phi.vercel.app
0 stars 0 forks source link

router replace vs router push #13

Open hudson221b opened 4 weeks ago

hudson221b commented 4 weeks ago

add more in this pr #12

hudson221b commented 3 weeks ago
  1. Setting searchParams with router.replace(url): When you use router.replace(url) in a client component to set search parameters, it updates the URL without adding a new entry to the browser's history stack.
  2. Navigating to another page: When you navigate to another page within your app, a new entry is added to the browser's history stack. Clicking the back button:
  3. When you click the back button in the browser, it will indeed take you back to the previous URL, including the search parameters you set. However, there are a few important points to consider:

Preservation of state: While the URL with the search parameters will be restored, any component state that was not persisted (e.g., in localStorage or a global state management solution) will be lost.

Hence it's important to sync searchParams with Zustand states. The URL should be the only source of truth. When searchParams are not set, for example, on /members page, we set states to a default value