si2030
si2030

Reputation: 4035

Aurelia - Update the menubar once a user has logged out

I have navmenu that needs to reloaded after a user logs out.

I have a logout.ts that essentially clears the JWT and loggedIn value.

    import { autoinject } from "aurelia-framework";
    import { TokenService } from "../../auth/tokenService"; z
    import { Router } from 'aurelia-router';

    @autoinject
    export class Logout {

        constructor(private tokenService: TokenService, public router: Router) {
            tokenService.clearJWT();

            this.router.refreshNavigation()
        }
    }

Thats all fine but I wanted to redirect to the home page but at the same time update the menu this time rechecking for loggedIn status.

I tried redirect, I have tried:

   this.router.navigateToRoute('home')

and the one above. In all cases the navmenu does not update. By updating the navmenu it will check for a loggedin value in localstorage and change the structure of the menu.

I also wanted it to go the home page after removing those items but more importantly how do I get it to refresh the navmenu?

Upvotes: 0

Views: 52

Answers (1)

Jeff G
Jeff G

Reputation: 2175

It sounds like you need to make sure your home route is refreshed even though it is already the current route. If so, in your configureRouter method, add activationStrategy.replace:

import {activationStrategy} from 'aurelia-router';

export class MyClass {
    configureRouter(config) {
        config.map([{
            route: 'home',
            name: 'home',
            activationStrategy: activationStrategy.replace,
            title: 'My Title',
            moduleId: 'myModule',
        }]);
    }
}

Upvotes: 1

Related Questions