在有角度的ui路线中编辑'哈希网址'

时间:2016-04-29 08:01:30

标签: angularjs url angular-ui-router

是否可以在#{1}}到/#/的哈希模式中编辑主题标签的位置?

不支持/#时(在较旧的浏览器中html5mode及以下),我获得IE9 hash URL /模式

我得到了什么:

hashbang

我想得到什么:

'index.com/#/path/id'

是否可以在角度应用配置中修改'index.com/path/#id' 的网址/展示位置?或者我想要一个未接受/无效的哈希模式URL?

2 个答案:

答案 0 :(得分:0)

在路由器页面中添加此代码

$locationProvider.html5Mode(true);

答案 1 :(得分:0)

您无法在不支持# API的浏览器中从网址中删除history

mode=truehtml5Mode

From AngularJS Doc

  

已启用 - {boolean} - (default: false)如果为true,将依赖   history.pushState更改支持的网址。将回归   不支持hash-prefixed的浏览器中的pushState个路径。

From $locationProvider source code,如果history.pushState失败,则会恢复旧的网址值:

function setBrowserUrlWithFallback(url, replace, state) {
      var oldUrl = $location.url();
      var oldState = $location.$$state;
      try {
        $browser.url(url, replace, state);

        // Make sure $location.state() returns referentially identical (not just deeply equal)
        // state object; this makes possible quick checking if the state changed in the digest
        // loop. Checking deep equality would be too expensive.
        $location.$$state = $browser.state();
      } catch (e) {
        // Restore old values if pushState fails
        $location.url(oldUrl);
        $location.$$state = oldState;

        throw e;
      }
    }
相关问题