Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs ui路由器:有没有办法在url的开头添加变量?_Angularjs_Angular Ui Router - Fatal编程技术网

Angularjs ui路由器:有没有办法在url的开头添加变量?

Angularjs ui路由器:有没有办法在url的开头添加变量?,angularjs,angular-ui-router,Angularjs,Angular Ui Router,我希望在我的路线中有这样一个变量: $stateProvider .state('edit', { url: ':organization/edit', templateUrl: 'partials/edit.html', controller: 'editController', controllerAs: 'editController' }) 让它在使用的同时工作 $urlRouterProvider

我希望在我的路线中有这样一个变量:

    $stateProvider
    .state('edit', {
        url: ':organization/edit',
        templateUrl: 'partials/edit.html',
        controller: 'editController',
        controllerAs: 'editController'
    })
让它在使用的同时工作

$urlRouterProvider.otherwise('index');
可能吗?因为我发现,当我试图去看电影时,另一条规则开始生效

myOrganization/edit

然后我被重定向到索引。我在这里遗漏了什么?

这应该是可能的,如图所示。技巧是将索引定义为第一个状态(不是第一个,而是在编辑之前):

.state('index'{
url:“/index”,
模板:'index',
})
.state('编辑'{
url:“/:组织/编辑”,
...
})
ui路由器
将按定义的状态逐个评估url状态。第一场比赛将决定胜负。因此,如果找到索引,在这种情况下,索引状态被选中

检查一下


我(私下)的建议是:不要指望秩序。尝试将状态定义为真正简单的标识。更重要的是,我的经验是,如果用户使用url,他们会复制/粘贴。。。所以,它可能会更健谈一些……

很高兴看到。。。如果可以的话,请考虑一下我的建议。。。只是建议;)
  .state('index',{
    url:'/index',
    template:'<div>index</div>',
  })
  .state('edit', {
    url: '/:organization/edit', 
    ...
  })