Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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路由器的默认路由_Angularjs_Angular Ui Router - Fatal编程技术网

Angularjs 角度ui路由器的默认路由

Angularjs 角度ui路由器的默认路由,angularjs,angular-ui-router,Angularjs,Angular Ui Router,angular ui路由器的示例演示在起始页有以下链接: “ui路由器”的完整url是/或http://angular-ui.github.io/ui-router/sample/#/ “about”的完整url是/about或http://angular-ui.github.io/ui-router/sample/#/about 当我使用durandalJS时,有一个限制,默认url只是“/”不能有“/ui路由器” angular ui路由器插件是否具有相同的限制?请参见默认路由的“否则”选项

angular ui路由器的示例演示在起始页有以下链接:

“ui路由器”的完整url是
/
http://angular-ui.github.io/ui-router/sample/#/

“about”的完整url是
/about
http://angular-ui.github.io/ui-router/sample/#/about

当我使用durandalJS时,有一个限制,默认url只是“/”不能有“/ui路由器”

angular ui路由器插件是否具有相同的限制?

请参见默认路由的“否则”选项


如果您谈论的是默认路由参数,那么有一个答案。

ui路由器的默认路由可以是您想要的任何路由,没有像DurandalJS中那样的限制。只需使用:

$stateProvider
    .state("otherwise", { url : '/otherwise'...})
这是ui路由器的官方文档,但我在其中找不到其他技术:


@apohi:ui路由器不是角路由。您的回复地址错误。

您可以这样做:

angular.module('MyApp', ['ui.router']).config([
  '$stateProvider', function ($stateProvider) {
     $stateProvider.state('default', {
     controller: 'MyController',
     templateUrl: 'path/to/index.html',
     url:''
  })
)];

这样,只要url位于站点的根目录上,ui路由器就会将其捕获到匹配的状态,在本例中为“默认值”。

使用$urlRouterProvider及其其他功能:

angular.module('MyApp', ['ui.router'])
  .config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
     $stateProvider.state('default', {
     controller: 'MyController',
     templateUrl: 'path/to/template.ng.html',
     url:'/default'
    })
    $urlRouterProvider.otherwise('/default')
  })];

否则,您可以使用$urlRouterProvide。如果您尝试导航到尚未定义的路由url,则此操作将起作用

摘自


最简单的方法

配置中添加$urlRouterProvider服务(函数($urlRouterProvider))

然后

app.config(function ($stateProvider, $urlMatcherFactoryProvider, $urlRouterProvider) {

         $urlRouterProvider.otherwise('employeesState'); //default route

         $stateProvider.state('employeesState', function(){
              //state configuration here
         }) //employees state

         $stateProvider.state('cutomersState', function(){
             //state configuration here
         })
}

在otherwise函数中指定您想要作为默认状态/路由的任何状态

@apohi:ui router!=为什么选择这个答案?角度路由器(ngRoute)不同于角度ui路由器(ui.router)。这可能会让初学者感到困惑。@boi_echos我是一个初学者,但从我在这个答案中看到的情况来看,它看起来是正确的。UI路由器具有
功能,否则
功能。你能指出什么是不正确的吗?我修复了第一个链接。@hofnarwillie这个答案说,
否则
是一个选项(例如,传入对象的属性)而不是一个函数。OP询问的是ui路由器,您的第一个链接指向angular-router上的文档。否则应该是对
$urlRouterProvider
的函数调用,而不是传递给
.state()
-除非您打算在默认路由上设置
url:'/others'
app.config(function ($stateProvider, $urlMatcherFactoryProvider, $urlRouterProvider) {

         $urlRouterProvider.otherwise('employeesState'); //default route

         $stateProvider.state('employeesState', function(){
              //state configuration here
         }) //employees state

         $stateProvider.state('cutomersState', function(){
             //state configuration here
         })
}