UI Router conditional ui views?

后端 未结 9 1414
遥遥无期
遥遥无期 2021-01-30 21:23

I can\'t figure out a reasonable way, which doesn\'t feel like a hack, to solve this rather trivial problem.

I want a guest to see a splash page when they access the ind

9条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-30 21:35

    Anywhere (probably in some high-level controller) you should be able to just bind a '$routeChangeStart' event to the $rootScope and do your check then:

    $rootScope.$on('$routeChangeStart', function(next, current){
        if(next != '/login' && !userLoggedIn){
            $location.path( "/login" );
        }
    });
    

    This will get fired every time a new route is set, even on the first visit to the page.

提交回复
热议问题