How can I cancel the ongoing navigation?

887 views Asked by At

I'm trying to prevent navigating to most of my sites' pages when user is not yet logged in. So this is the code I started to write to solve that issue:

router.on("router:navigation:processing", function (instruction, usedRouter) {

    if (!userLoggedIn && instruction.config.moduleId !== "login") {
        router.navigate('login'); //no better way???
    }
}

I would like to find a better alternative to the "router.navigate()"... Didn't find any instruction.cancelNavigation() or anything like that...

1

There are 1 answers

0
chrisdot On BEST ANSWER

OK, linked to Conditional routing in Durandal (see how to code it and the official doc about it)

Thanks @Matthew !