Ember.js,EmberCLI - 从URL中删除哈希(#)

JDi*_*522 11 ember.js ember-cli

因此,根据Ember的文档, Ember默认使用hashchange事件.这就是为什么我们有花哨的#/some/url设置.我们还可以将其设置为使用浏览器的历史 API.

我注意到Built with Ember上列出的大多数(如果不是全部)网站显然都使用了历史API.这是有道理的,因为它使URL看起来更自然.

所有这一切都说我(sorta)了解在哪里,如何以及为什么要加以#解决.

我的问题与EmberCLI有关.我注意到,当我创建一个简单的应用程序时,#它不在URL中.那是因为我还没有部署它吗?或者CLI默认为历史API?如果是这样,这套装置在哪里?我找不到一个例子

App.Router.reopen({
  location: 'history'
});
Run Code Online (Sandbox Code Playgroud)

Kin*_*n2k 14

我点击的第一个使用哈希历史记录;) https://fnd.io/

默认情况下,Ember使用散列更改事件,主要是由于跨浏览器兼容性. http://caniuse.com/history

在ember-cli中,它auto默认使用. http://emberjs.com/api/classes/Ember.Location.html#toc_autolocation

如果你看,router.js你会注意到

var Router = Ember.Router.extend({
  location: YourAppENV.locationType
});
Run Code Online (Sandbox Code Playgroud)

从中提取其设置 config/environment.js

module.exports = function(environment) {
  var ENV = {
    baseURL: '/',
    locationType: 'auto',
    EmberENV: {
    ....
Run Code Online (Sandbox Code Playgroud)

就像快速插件一样,位置历史记录设置起来有点困难,因为你必须告诉你的服务器在它被命中时从基页提供服务,并在之后忽略任何内容,但它实际上只是一次性设置.