Router
Ember.Router Class
PUBLIC
Extends: Ember.Object
Uses: Ember.Evented
Defined in: packages/ember-routing/lib/system/router.js:51
Module: ember-routing
The Ember.Router
class manages the application state and URLs. Refer to the routing guide for documentation.
_deserializeQueryParam (value, defaultType) private
Deserializes the value of a query parameter based on a default type
Parameters:
-
value
Object
-
defaultType
String
_deserializeQueryParams (handlerInfos, queryParams) Void
private
Deserializes the given query params according to their QP meta information.
Parameters:
-
handlerInfos
Array
-
queryParams
Object
Returns:
-
Void
_fullyScopeQueryParams (leafRouteName, contexts, queryParams) Void
private
Maps all query param keys to their fully scoped property name of the form controllerName:propName
.
Parameters:
-
leafRouteName
String
-
contexts
Array
-
queryParams
Object
Returns:
-
Void
_getQPMeta (handlerInfo) Object
private
Returns the meta information for the query params of a given route. This will be overriden to allow support for lazy routes.
Parameters:
-
handlerInfo
HandlerInfo
Returns:
-
Object
_hydrateUnsuppliedQueryParams (state, queryParams) Void
private
Hydrates (adds/restores) any query params that have pre-existing values into the given queryParams hash. This is what allows query params to be "sticky" and restore their last known values for their scope.
Parameters:
-
state
TransitionState
-
queryParams
Object
Returns:
-
Void
_prepareQueryParams (targetRouteName, models, queryParams) Void
private
Prepares the query params for a URL or Transition. Restores any undefined QP keys/values, serializes all values, and then prunes any default values.
Parameters:
-
targetRouteName
String
-
models
Array
-
queryParams
Object
Returns:
-
Void
_pruneDefaultQueryParamValues (handlerInfos, queryParams) Void
private
Removes (prunes) any query params with default values from the given QP object. Default values are determined from the QP meta information per key.
Parameters:
-
handlerInfos
Array
-
queryParams
Object
Returns:
-
Void
_queryParamsFor (handlerInfos) Object
private
Returns a merged query params meta object for a given set of handlerInfos. Useful for knowing what query params are available for a given route hierarchy.
Parameters:
-
handlerInfos
Array
Returns:
-
Object
_serializeQueryParam (value, type) private
Serializes the value of a query parameter based on a type
Parameters:
-
value
Object
-
type
String
_serializeQueryParams (handlerInfos, queryParams) Void
private
Serializes the given query params according to their QP meta information.
Parameters:
-
handlerInfos
Arrray
-
queryParams
Object
Returns:
-
Void
didTransitionpublic
Handles updating the paths and notifying any listeners of the URL change.
Triggers the router level didTransition
hook.
For example, to notify google analytics when the route changes, you could use this hook. (Note: requires also including GA scripts, etc.)
let Router = Ember.Router.extend({ location: config.locationType, didTransition: function() { this._super(...arguments); return ga('send', 'pageview', { 'page': this.get('url'), 'title': this.get('url') }); } });
hasRouteBoolean
private
Does this router instance have the given route.
Returns:
-
Boolean
isActive (routeName) Boolean
private
Determines if the supplied route is currently active.
Parameters:
- routeName
Returns:
-
Boolean
isActiveIntent (routeName, models, queryParams) Boolean
private
An alternative form of isActive
that doesn't require manual concatenation of the arguments into a single array.
Parameters:
- routeName
- models
- queryParams
Returns:
-
Boolean
map (callback) public
The Router.map
function allows you to define mappings from URLs to routes in your application. These mappings are defined within the supplied callback function using this.route
.
The first parameter is the name of the route which is used by default as the path name as well.
The second parameter is the optional options hash. Available options are:
-
path
: allows you to provide your own path as well as mark dynamic segments. -
resetNamespace
: false by default; when nesting routes, ember will combine the route names to form the fully-qualified route name, which is used with{{link-to}}
or manually transitioning to routes. SettingresetNamespace: true
will cause the route not to inherit from its parent route's names. This is handy for preventing extremely long route names. Keep in mind that the actual URL path behavior is still retained.
The third parameter is a function, which can be used to nest routes. Nested routes, by default, will have the parent route tree's route name and path prepended to it's own.
App.Router.map(function(){ this.route('post', { path: '/post/:post_id' }, function() { this.route('edit'); this.route('comments', { resetNamespace: true }, function() { this.route('new'); }); }); });
For more detailed documentation and examples please see the guides.
Parameters:
- callback
resetprivate
Resets the state of the router by clearing the current route handlers and deactivating them.
startRoutingprivate
Initializes the current router instance and sets up the change handling event listeners used by the instances location
implementation.
A property named initialURL
will be used to determine the initial URL. If no value is found /
will be used.
transitionTo (name, models, options) Transition
public
Transition the application into another route. The route may be either a single route or route path:
See Route.transitionTo for more info.
Parameters:
-
name
String
- the name of the route or a URL
-
models
...Object
- the model(s) or identifier(s) to be used while transitioning to the route.
-
options
[Object]
- optional hash with a queryParams property containing a mapping of query parameters
Returns:
-
Transition
- the transition object associated with this attempted transition
urlString
private
Represents the current URL.
Returns:
-
String
- The current URL.
willTransitionpublic
Handles notifying any listeners of an impending URL change.
Triggers the router level willTransition
hook.
locationpublic
The location
property determines the type of URL's that your application will use.
The following location types are currently available:
-
history
- use the browser's history API to make the URLs look just like any standard URL -
hash
- use#
to separate the server part of the URL from the Ember part:/blog/#/posts/new
-
none
- do not store the Ember URL in the actual browser URL (mainly used for testing) -
auto
- use the best option based on browser capabilites:history
if possible, thenhash
if possible, otherwisenone
Note: If using ember-cli, this value is defaulted to auto
by the locationType
setting of /config/environment.js
Default: 'hash'
rootURLpublic
Represents the URL of the root of the application, often '/'. This prefix is assumed on all routes defined on this router.
Default: '/'
© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://emberjs.com/api/classes/Ember.Router.html