Aurelia 带“的资产净值项目”;绑定";导航到路线后不显示

Aurelia 带“的资产净值项目”;绑定";导航到路线后不显示,aurelia,Aurelia,我的aurelia应用程序没有显示绑定到用户是否登录的特定导航项,这使我面临一个问题。信息技术他快把我逼疯了,我希望这里有人能帮上忙 我有一个app.js和app.html,其中有登录代码(使用Auth0)。请看下面的内容,我已经尽可能地进行了全面的评论 app.js // I've imported a couple of stuff here for the code below to work export class App { lock = new Auth0Lock('XXX

我的aurelia应用程序没有显示绑定到用户是否登录的特定导航项,这使我面临一个问题。信息技术他快把我逼疯了,我希望这里有人能帮上忙

我有一个app.js和app.html,其中有登录代码(使用Auth0)。请看下面的内容,我已经尽可能地进行了全面的评论

app.js

// I've imported a couple of stuff here for the code below to work
export class App {
    lock = new Auth0Lock('XXXXXXXX');
    isAuthenticated = false;

    constructor(http, router) {
        this.http = http;
        this.router = router;

        this.router.configure(config => {
            config.title = 'Sample App';
            config.map([
                {
                    route: ['', 'welcome'],
                    name: 'welcome',
                    moduleId: 'welcome',
                    nav: true,
                    title: 'Welcome',
                    settings: {
                        icon: 'fa-home'
                    }
                },
                {
                    route: ['form'],
                    name: 'form',
                    moduleId: 'form',
                    nav: false,
                    title: 'Provide your Details',
                    settings: {
                        icon: 'fa-user'
                    }
                }
            ]);
            config.mapUnknownRoutes({redirect: '#/'});
        });

        http.configure(config => {
            config
                .useStandardConfiguration()
        });

        this.isAuthenticated = tokenIsExpired() ? false : true; // checks whether the token from Auth0 is expired or still valid
    };

    login() {
        // If the user is successful, the code below gets executed
        this.isAuthenticated = true;
        this.router.navigate('form'); // When the user logs in, they go to the page "form"
    }

    logout() {
        // Logout Code
    }
}
import {bindable} from 'aurelia-framework';
import {tokenIsExpired} from 'tokenUtils'; // tokenUtils is a js which checks for expired tokens

@inject(Router)

export class NavBar {
    @bindable router = null
    isAuthenticated = false;

    constructor(router) {
        this.isAuthenticated = tokenIsExpired() ? false : true;
    }
}
navbar.js

// I've imported a couple of stuff here for the code below to work
export class App {
    lock = new Auth0Lock('XXXXXXXX');
    isAuthenticated = false;

    constructor(http, router) {
        this.http = http;
        this.router = router;

        this.router.configure(config => {
            config.title = 'Sample App';
            config.map([
                {
                    route: ['', 'welcome'],
                    name: 'welcome',
                    moduleId: 'welcome',
                    nav: true,
                    title: 'Welcome',
                    settings: {
                        icon: 'fa-home'
                    }
                },
                {
                    route: ['form'],
                    name: 'form',
                    moduleId: 'form',
                    nav: false,
                    title: 'Provide your Details',
                    settings: {
                        icon: 'fa-user'
                    }
                }
            ]);
            config.mapUnknownRoutes({redirect: '#/'});
        });

        http.configure(config => {
            config
                .useStandardConfiguration()
        });

        this.isAuthenticated = tokenIsExpired() ? false : true; // checks whether the token from Auth0 is expired or still valid
    };

    login() {
        // If the user is successful, the code below gets executed
        this.isAuthenticated = true;
        this.router.navigate('form'); // When the user logs in, they go to the page "form"
    }

    logout() {
        // Logout Code
    }
}
import {bindable} from 'aurelia-framework';
import {tokenIsExpired} from 'tokenUtils'; // tokenUtils is a js which checks for expired tokens

@inject(Router)

export class NavBar {
    @bindable router = null
    isAuthenticated = false;

    constructor(router) {
        this.isAuthenticated = tokenIsExpired() ? false : true;
    }
}
navbar.html


切换导航
//左侧导航栏工作正常
从上面的代码可以看出,当有人单击app.html文件中的login时,他们将进行Auth0验证,成功后,他们将被重定向到表单页面。但是,在上,一旦用户被重定向,他们就无法看到绑定了isAuthenticated的链接。链接仅在我重新加载页面时出现


我不知道我做错了什么,我希望得到指导,让这项工作。谢谢你的时间

问题在于导航栏的函数
tokenIsExpired()
只被调用一次。因此,导航栏的
已验证
未更新。这就是DOM没有更新的原因

要解决此问题,请创建另一个可绑定属性,以告知导航栏用户是否已登录。例如:

export class NavBar {
    @bindable router;
    @bindable isAuthenticated;

    //remove the old constructor
}
现在,在应用程序html中,将
isAuthenticated
绑定到
NavBar

<nav-bar router.bind="router" is-authenticated.bind="isAuthenticated"></nav-bar>


希望这有帮助

问题在于导航栏的函数
tokenIsExpired()
只被调用一次。因此,导航栏的
已验证
未更新。这就是DOM没有更新的原因

要解决此问题,请创建另一个可绑定属性,以告知导航栏用户是否已登录。例如:

export class NavBar {
    @bindable router;
    @bindable isAuthenticated;

    //remove the old constructor
}
现在,在应用程序html中,将
isAuthenticated
绑定到
NavBar

<nav-bar router.bind="router" is-authenticated.bind="isAuthenticated"></nav-bar>


希望这有帮助

哦,哇!谢谢这让我走上了解决问题的正确道路!!伟大的我很感激!哦,哇!谢谢这让我走上了解决问题的正确道路!!伟大的我很感激!