Verifying route preconditions prior to loading controller

前端 未结 4 689
广开言路
广开言路 2021-02-15 17:27

I\'m writing a single page application in Angular, specifically angular.dart, but I\'m assuming this question still applies to AngularJS.

Take for example the followin

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-15 18:09

    Well, I made a thing in Dart which is close to one of the previous solutions which don't really work. The main point is that in the RouteEventHandler, you need to call the RouteEventHandler of the view.

          ..addRoute(
              name: 'userAdd',
              path: '/userAdd',
              enter: checkAuthentication(router,view,'view/addUser.html'))
          ..addRoute(
            name: 'login',
            path: '/login',
            enter: view('view/login.html'));
      }
    
      RouteEventHandler checkAuthentication(Router router,ViewFactory view, String location){
         return (RouteEvent e) {
          if(_authenticationService.isAuthenticated()){
            view(location)(e);
          }else{
            router.go("login",{});
          }
        };
      }
    

提交回复
热议问题