nativescript-vue / nativescript-vue-navigator

A simple router for NativeScript-Vue, built on top of $navigateTo to simplify routing from within components
MIT License
98 stars 10 forks source link

$navigator.path not up-to-date on mounted() after navigation #42

Open coltonwood opened 4 years ago

coltonwood commented 4 years ago

I have a pretty simple setup:

Let me know if you need more details. The setup seems pretty basic, so maybe I'm just missing something obvious. I'd like to check if a component needs auth (in my meta prop of the route) on mounted, so that's my actual use case.

Note I'm on 1.2.0.

coltonwood commented 4 years ago

After some more investigation, it looks like the $navigator.path is not updated (and therefore can't get meta options from route) until after the transition animation is complete.

Is this intended?

rigor789 commented 4 years ago

The path is updated when the Frame updates it's current page - which happens to be right when the transition finishes, which is after the mounted hook - so that part is expected.

I guess you should not navigate if the target needs auth, but that's not currently possible without manually reading the routes file and the meta. I'll think about a neat solution, perhaps a beforeNavigate hook where you can cancel/change the target route.

coltonwood commented 4 years ago

Ooh yeah that could be pretty useful I think. Thanks for the explanation.