adbrosaci / vue-lang-router

Vue language routing with (optional) localized URLs.
MIT License
65 stars 8 forks source link

How to deal with navigation guards? #11

Open SylvainBigonneau opened 3 years ago

SylvainBigonneau commented 3 years ago

I am trying to use vue-router's beforeRouteLeave helper to add some guarding logic, but it seems that the localized redirection from vue-lang-router is acting in the process, essentially triggering my navigation guards twice... (once for the original URI, then for the localized one)

Anybody has a clean or clever solution to avoid this?

radek-altof commented 3 years ago

Hi @SylvainBigonneau, yes, Vue Language Router's switching logic is using beforeEach navigation guard of Vue Router. I can imagine this can somehow interfere with other guarding logic, depending on what you're trying to implement.

However, I tried adding beforeRouteLeave to a component and it's being triggered only once. I'm unable to replicate your issue. Can you provide some sample demo? Also, are you using Vue 2 or Vue 3? Among other things, Vue Router changed alias logic between these versions, which in turn affected Vue Language Router a bit, so there might be a difference.

One last point, Vue Router provides many types of navigation guards, perhaps another one will work for you.