The location API

At the start of this chapter, when we were discussing about the router.js, or the application router that manages different URL states of the application, we passed in the location property to our Router object. The property was being read from config/environment.js file:

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

The Router definition is present at example1/app/router.js

If you look into the config/environment.js file, you will see that the location property is set to auto for development and production environments and for test environments it is set to none.

The location API governs how to generate URLs for your application. The location property can be assigned one of these four values: hash, history, auto, and none.

If you set the location property of your router to hash, then the generated URLs of your application will have a # in them and will be of the form /#/route. This type of location tracking depends on the hashchange event existing in the browser to detect any changes in the URL.

The history location type is more recent and is available in latest browsers (IE 10+, Firefox 31+, Chrome 31+) only. This will result in URLs that are similar to the normal URLs, that is, without the #. This technique uses the browser's history API to keep track of URL changes. The resulting URLs will be of the form /route.

The auto-location type decides on which type to use, based on the browser. If the browser supports the history API, the application will use history as the location type, otherwise it will fall back to hash location type.

The last location type available is none. If you set your router's location type to none, then your router will not store the application URL state in the URL and the URL will remain constant throughout the application. This type of location is generally used for testing purposes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.104.124