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

Defined in packages/ember-routing/lib/system/router.js:714

Deserializes the value of a query parameter based on a default type

Parameters:

value Object
defaultType String

_deserializeQueryParams (handlerInfos, queryParams) Voidprivate

Defined in packages/ember-routing/lib/system/router.js:694

Deserializes the given query params according to their QP meta information.

Parameters:

handlerInfos Array
queryParams Object

Returns:

Void

_fullyScopeQueryParams (leafRouteName, contexts, queryParams) Voidprivate

Defined in packages/ember-routing/lib/system/router.js:884

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) Objectprivate

Defined in packages/ember-routing/lib/system/router.js:812

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) Voidprivate

Defined in packages/ember-routing/lib/system/router.js:921

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) Voidprivate

Defined in packages/ember-routing/lib/system/router.js:794

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) Voidprivate

Defined in packages/ember-routing/lib/system/router.js:734

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) Objectprivate

Defined in packages/ember-routing/lib/system/router.js:826

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

Defined in packages/ember-routing/lib/system/router.js:678

Serializes the value of a query parameter based on a type

Parameters:

value Object
type String

_serializeQueryParams (handlerInfos, queryParams) Voidprivate

Defined in packages/ember-routing/lib/system/router.js:656

Serializes the given query params according to their QP meta information.

Parameters:

handlerInfos Arrray
queryParams Object

Returns:

Void

didTransitionpublic

Defined in packages/ember-routing/lib/system/router.js:223
Available since 1.2.0

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')
    });
  }
});

hasRouteBooleanprivate

Defined in packages/ember-routing/lib/system/router.js:439

Does this router instance have the given route.

Returns:

Boolean

isActive (routeName) Booleanprivate

Defined in packages/ember-routing/lib/system/router.js:405

Determines if the supplied route is currently active.

Parameters:

routeName

Returns:

Boolean

isActiveIntent (routeName, models, queryParams) Booleanprivate

Defined in packages/ember-routing/lib/system/router.js:418
Available since 1.7.0

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

Defined in packages/ember-routing/lib/system/router.js:1321

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. Setting resetNamespace: 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

Defined in packages/ember-routing/lib/system/router.js:450

Resets the state of the router by clearing the current route handlers and deactivating them.

startRoutingprivate

Defined in packages/ember-routing/lib/system/router.js:177

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) Transitionpublic

Defined in packages/ember-routing/lib/system/router.js:352

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

urlStringprivate

Defined in packages/ember-routing/lib/system/router.js:154

Represents the current URL.

Returns:

String
The current URL.

willTransitionpublic

Defined in packages/ember-routing/lib/system/router.js:321
Available since 1.11.0

Handles notifying any listeners of an impending URL change.

Triggers the router level willTransition hook.

locationpublic

Defined in packages/ember-routing/lib/system/router.js:62

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, then hash if possible, otherwise none

Note: If using ember-cli, this value is defaulted to auto by the locationType setting of /config/environment.js

Default: 'hash'

rootURLpublic

Defined in packages/ember-routing/lib/system/router.js:82

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

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部