UI路由器抽象状态没有url

时间:2016-01-02 13:28:11

标签: angularjs angular-ui-router

使用UI-Router定义抽象状态的方法如下:

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

  $urlRouterProvider.otherwise('/blog/home');

  $stateProvider

  // abstract state
  .state('blog', {
    url: '/blog',
    templateUrl: '/templates/navbar.html',
    abstract: true,
    controller:'NavBarCtrl as navbar',
  })

  // home
  .state('blog.home', {
    url: '/home',
    templateUrl: '/templates/home.html',
    controller:'HomeCtrl as home',
  })

 ...
})

当您导航到州首页时,您将转到该域:

yourcustomdomain.com/blog/home

有没有办法定义抽象状态的url,使其不显示前缀blog,因此:

yourcustomdomain.com/home?

1 个答案:

答案 0 :(得分:4)

只需从抽象状态删除网址

.state('blog', {
  url: '',
  templateUrl: '/templates/navbar.html',
  abstract: true,
  controller:'NavBarCtrl as navbar',
})
相关问题