Ember.js, EmberCLI - removing the hash ( # ) from the URL

杀马特。学长 韩版系。学妹 提交于 2019-12-05 01:05:31

The first one I clicked used hash history ;) https://fnd.io/

By default Ember uses the hash change event, mostly due to cross browser compatibility. http://caniuse.com/history

In ember-cli it uses auto by default. http://emberjs.com/api/classes/Ember.Location.html#toc_autolocation

If you look in router.js you'll notice

var Router = Ember.Router.extend({
  location: YourAppENV.locationType
});

which pulls its settings from 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.

For locationType: 'auto' Your routes will be http://localhost:4200/login

For locationType: 'hash' Your routes will be http://localhost:4200/#/login

That's it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!