nativescript-vue-navigator icon indicating copy to clipboard operation
nativescript-vue-navigator copied to clipboard

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

Open coltonwood opened this issue 5 years ago • 3 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.

coltonwood avatar Jun 17 '20 16:06 coltonwood

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?

coltonwood avatar Jun 17 '20 16:06 coltonwood

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.

rigor789 avatar Jun 17 '20 16:06 rigor789

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

coltonwood avatar Jun 17 '20 16:06 coltonwood