AngularJS ui路由器强制参数

前端之家收集整理的这篇文章主要介绍了AngularJS ui路由器强制参数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
根据文档,angularjs ui-router url参数默认是可选的.那么有没有办法创建强制参数?就像参数丢失或为null时,它不会进入页面

希望您能够帮助我.

谢谢

解决方法

使用UI路由器 resolve检查路由参数是否丢失.

//Example of a single route
.state('dashboard',{
  url: '/dashboard/:userId',templateUrl: 'dashboard.html',controller: 'DashboardController',resolve: function($stateParams,$location){

    //Check if url parameter is missing.
    if ($stateParams.userId === undefined) {
      //Do something such as navigating to a different page.
      $location.path('/somewhere/else');
    }
  }
})

猜你在找的Angularjs相关文章