UI-Router:为什么有一个领先的" /"在我孩子的国家/地区?

时间:2014-08-26 10:12:25

标签: angularjs angular-ui angular-ui-router

我正在使用AngularJS和ui-router。我的项目根位于/,而我的角度应用位于/panel/

我有5种状态:loginlogoutmain抽象州),main.homemain.holiday

一切似乎都很好,我可以访问main.homeloginlogout。但是,当我访问main.holiday时,我注意到有一个前导斜杠 /panel//holiday

这里是每个州的gist(我认为将每个片段放在这里都不错)。

我的SPA HTML:

<!-- ... -->
<head>
<base href="/panel/">
</head>
<!-- ..-->

我认为这是某种错误,不是吗?顺便说一句,这里有plnkr的链接,我似乎在那里重现了这个问题。

2 个答案:

答案 0 :(得分:1)

从我的Reddit回复中复制(虽然我似乎不是第一个报名的人):

// This can have an empty URL unless it needs to add something useful
// For example, it could be '/www' but '/' is pointless and the cause of your issue
var main = {
  name: 'main',
  abstract: true,
  url: '',
  template: '<div ui-view></div>'
};

此外:

// Add a '/' URL to this state since it's not abstract.
// Else changing from another state to this one won't impact the URL, which is weird
var home = {
  name: 'main.home',
  url: '/',
  template: 'You are in main.home'
};

答案 1 :(得分:0)

我用两种方法解决了这个问题:

  1. 通过简单删除url 抽象状态的main属性。或者,
  2. url abstract 状态的main属性设置为空字符串(url: '')。