4.8 Routing -- Specifying The URL Type

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了4.8 Routing -- Specifying The URL Type相关的知识,希望对你有一定的参考价值。

1. 默认的路由器使用浏览器的hash来加载应用程序的开始状态并且当你移动时同步保持。目前,这依赖于浏览器中存在的hashchange事件。

2. 假设下面的路由器,输入/#/posts/new将会把你带到posts.new路由。

app/router.js

Router.map(function() {
  this.route(‘posts‘, function() {
    this.route(‘new‘);
  });
});
  • 如果你想移除开头的/#使URL使简单的/posts/new,你可以告诉路由器使用浏览器的history API。

3. 记住服务器必须必须为Ember app服务,来自Router.map function中定义的所有URL。

app/router.js

Ember.Router.extend({
  location: ‘history‘
});

4. 通过为location指定auto,你可以告诉Ember去使用基于浏览器支持最好的location选项。Ember将使用history,如果用户的浏览器支持,否则跌回hash。

5. 最后,如果你一点也不希望用户浏览器的URL和你的app交互,你可以完全禁用location API。这对测试很有用,或者当你需要使用你的路由器管理状态,但是暂时不想让它污染URL(例如当你把app嵌入到一个更大的页面)。

app/router.js

Ember.Router.extend({
  location: ‘none‘
});

以上是关于4.8 Routing -- Specifying The URL Type的主要内容,如果未能解决你的问题,请参考以下文章

指定表单使用的路由 Specifying the Route Used by a Form

IMMDevice::Activate and specifying IID_IBaseFilter as the interface identifier

[Angular] Fetch non-JSON data by specifying HttpClient responseType in Angular

'Specifying a namespace in include() without providing an app_name '

idea scala 报 with UTF-8 Please try specifying another one using the -encoding option

'Specifying a namespace in include() without providing an app_name '