vuejs / router

🚦 The official router for Vue.js
https://router.vuejs.org/
MIT License
3.77k stars 1.16k forks source link

Allow multiple push with different state within the same path #2294

Open sjquant opened 3 weeks ago

sjquant commented 3 weeks ago

What problem is this solving

Currently, Vue Router prevents pushing the same path multiple times, even if the state differs. This restriction limits the ability to manage state changes effectively within the same route. I propose an enhancement to allow multiple pushes to the same path if the state is different. me.

Benefits

Providing this feature will align Vue Router with modern state management practices and enhance its capabilities in dynamic applications.

Thank you for considering this enhancement. I look forward to your feedback and any further discussion on this proposal.

Proposed solution

Implement a check within the push method to determine if the state has changed. If the state is different, allow the push to proceed even if the path is the same. (maybe check state change in isSameRouteLocation)

Describe alternatives you've considered

As a temporary workaround, we can append a query parameter to the path, but this approach clutters the URL, and there are times when changing URL is not ideal.

posva commented 3 weeks ago

Currently, you need to add the force: true option to router.push() (or preferably router.replace() for this to work), but it's currently internal and shouldn't be needed correct cases.