nativescript-vue / nativescript-vue-navigator

A simple router for NativeScript-Vue, built on top of $navigateTo to simplify routing from within components

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

coltonwood opened this issue · comments

I have a pretty simple setup:

  • A basic login component that calls this.$navigator.navigate('/landing').
  • The Landing component just console.logs this.$navigator.path within mounted and it spits out /login instead of /landing
  • The Landing template has a Label with $navigator.path and I see it update a split second after rendering, so it seems like there's just a delay when path is actually updated? I'm not sure.

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.

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?

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.

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