Ember.js,EmberCLI - 从URL中删除哈希(#) [英] Ember.js, EmberCLI - removing the hash ( # ) from the URL
问题描述
因此,根据 Ember的文档,Ember默认使用 hashchange 事件。这就是为什么我们有花式#/ some / url
设置。我们还可以将其设置为使用浏览器的历史 API。
So according to Ember's documentation Ember defaults to using the hashchange event. Thats why we have the fancy #/some/url
setup. We can also set it to use the browser's history API.
我有注意到,使用Ember构建的大多数(如果不是全部)网站显然使用了历史API。这是有道理的,因为它使URL看起来更自然。
I've noticed that most (if not all) sites listed on Built with Ember apparently use the history API. Which makes sense because it make the URL look more natural.
所有这一切都是说我(sorta)了解在哪里,如何以及为什么 #
得到解决。
All that is to say I (sorta) understand where, how, and why the #
gets tacked on.
我的问题具体涉及EmberCLI。我注意到,当我创建一个简单的应用程序时,#
不在URL中。是因为我没有部署吗?还是CLI默认为历史记录?如果是这样,这个设置在哪里?我找不到一个
My question relates specifically to EmberCLI. I've noticed that when I create a simple app the #
is not in the URL. Is that because I havent deployed it yet? Or does the CLI default to the history api? If so, where is this set? I cant find an instance of
App.Router.reopen({
location: 'history'
});
推荐答案
第一个我点击使用哈希历史; a href =https://fnd.io/ =noreferrer> https://fnd.io/
The first one I clicked used hash history ;) https://fnd.io/
默认情况下Ember使用散列变化事件,主要是由于跨浏览器的兼容性。 http://caniuse.com/history
By default Ember uses the hash change event, mostly due to cross browser compatibility. http://caniuse.com/history
在ember-cli默认使用 auto
。 http://emberjs.com/api/classes/Ember.Location.html#toc_autolocation
In ember-cli it uses auto
by default. http://emberjs.com/api/classes/Ember.Location.html#toc_autolocation
如果您查看 router.js
,您会注意到
If you look in router.js
you'll notice
var Router = Ember.Router.extend({
location: YourAppENV.locationType
});
从 config / environment.js
module.exports = function(environment) {
var ENV = {
baseURL: '/',
locationType: 'auto',
EmberENV: {
....
作为一个快速插件,位置记录更难设置,因为
基本上必须告诉您的服务器从基本页面发送,只要它被击中,并忽略任何东西后那个,但它只是一次性设置。
Just as a quick plug, location history is a tad more difficult to set up, since you essentially have to tell your server to serve from the base page whenever it's hit, and ignore anything after that, but it's really just a one time setup.
这篇关于Ember.js,EmberCLI - 从URL中删除哈希(#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!