Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow push and replace to take parameters other than query and hash #3

Open
dongyeop-youha opened this issue Nov 9, 2022 · 0 comments

Comments

@dongyeop-youha
Copy link
Contributor

dongyeop-youha commented Nov 9, 2022

It allows for batchRouter to completely replace original router for changing URL.

It is also needed because when changing pathname via router and changing query via batchRouter happens simultaneously, query change might overwrite pathname change resulting in unwanted behavior.

When pathname is changed, query change requests must be ignored. This is because query change request in that page intends the change in that page, but the page itself will be replaced so query param must be cleared.

However, query param in the same call as the pathname change must be applied to the URL.

Therefore, if pathname change is requested to the batchRouter, it will pass it to the original router, and set a flag to ignore all query change requests. After the pathname change, the flag must be removed.

One example that would require this behavior, is when one useEffect checks the cookie to see if the user has signed in, and redirect to signin page if not. And another useEffect might try to set a query parameter in the URL as a default value.
It will call router.push multiple times, resulting in overwritten URL state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant