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

Meta Info Bug. Not Updating #30

Closed juanbonoso closed 4 years ago

juanbonoso commented 4 years ago

Hi,

First, thanks for this awesome plugin , i really like it.

I just realized that meta info, is not being update when i pass from one page to another with this.$navigator.navigate();

I use the loaded page event from nativescript to verify if the user have autorization to open a particular page:

public loadPage() {
        this.store.auth.isLoggedIn().then(isLoggedIn => {
            if (!isLoggedIn) {
                console.log(this.$navigator.route.meta.needsAuth);
                console.log(JSON.stringify(this.$navigator.route.meta));
                if (this.$navigator.route.meta.needsAuth) {
                    // this.$navigator.navigate('/OnBoard', { clearHistory: true });
                }
            }
        });

The console.log will always show:
true '{"needsAuth":true,"name":"AdminInterface"}'

AdminInterface is the page, where loadPage is triggered. I also have the same loadPage in OnBoard where triggers the same output from AdminInterface all the time, which makes my app to enter in infinite Loop, navigating every second to OnBoard.

routes file:

'/OnBoard': {
        component: OnBoard,
        meta: {
            needsAuth: false,
            name: 'OnBoard',
        },
        props: {
            userType: '',
        },
    },
'/AdminInterface': {
        component: AdminInterface,
        meta: {
            needsAuth: true,
            name: 'AdminInterface',
        },
        props: {
            userType: '',
        },
    }
rigor789 commented 4 years ago

I suspect the meta is not yet showing the new route's meta in the @loaded event. Can you try adding a slight delay with setTimeout just to confirm the case?

juanbonoso commented 4 years ago

@rigor789 I just tried it with a setTimeOut of 10 seconds (10000 miliseconds), and did not work. So it is not the loaded event.

superalex commented 4 years ago

@juanbonoso are you using using class style Vue components?

juanbonoso commented 4 years ago

@superalex I am using vue class components.

superalex commented 4 years ago

So I think we have the same issue: https://github.com/nativescript-vue/nativescript-vue-navigator/issues/31

juanbonoso commented 4 years ago

Yes, I just read your issue and we have the same problem.

rigor789 commented 4 years ago

Let's consolidate this into #31