Class Route

public
import Route from '@ember/routing/route';

The Route class is used to define individual routes. Refer to the routing guide for documentation.

Show:

Module: @ember/routing

Defines the properties that will be concatenated from the superclass (instead of overridden).

By default, when you extend an Ember class a property defined in the subclass overrides a property with the same name that is defined in the superclass. However, there are some cases where it is preferable to build up a property's value by combining the superclass' property value with the subclass' value. An example of this in use within Ember is the classNames property of Component from @ember/component.

Here is some sample code showing the difference between a concatenated property and a normal one:

import EmberObject from '@ember/object';

const Bar = EmberObject.extend({
  // Configure which properties to concatenate
  concatenatedProperties: ['concatenatedProperty'],

  someNonConcatenatedProperty: ['bar'],
  concatenatedProperty: ['bar']
});

const FooBar = Bar.extend({
  someNonConcatenatedProperty: ['foo'],
  concatenatedProperty: ['foo']
});

let fooBar = FooBar.create();
fooBar.get('someNonConcatenatedProperty'); // ['foo']
fooBar.get('concatenatedProperty'); // ['bar', 'foo']

This behavior extends to object creation as well. Continuing the above example:

let fooBar = FooBar.create({
  someNonConcatenatedProperty: ['baz'],
  concatenatedProperty: ['baz']
})
fooBar.get('someNonConcatenatedProperty'); // ['baz']
fooBar.get('concatenatedProperty'); // ['bar', 'foo', 'baz']

Adding a single property that is not an array will just add it in the array:

let fooBar = FooBar.create({
  concatenatedProperty: 'baz'
})
view.get('concatenatedProperty'); // ['bar', 'foo', 'baz']

Using the concatenatedProperties property, we can tell Ember to mix the content of the properties.

In Component the classNames, classNameBindings and attributeBindings properties are concatenated.

This feature is available for you to use throughout the Ember object model, although typical app developers are likely to use it infrequently. Since it changes expectations about behavior of properties, you should properly document its usage in each individual concatenated property (to not mislead your users to think they can override the property in a subclass).

Module: @ember/routing

Available since v1.6.0

The controller associated with this route.

Example

app/routes/form.js
import Route from '@ember/routing/route';
import { action } from '@ember/object';

export default class FormRoute extends Route {
  @action
  willTransition(transition) {
    if (this.controller.get('userHasEnteredData') &&
        !confirm('Are you sure you want to abandon progress?')) {
      transition.abort();
    } else {
      // Bubble the `willTransition` action so that
      // parent routes can decide whether or not to abort.
      return true;
    }
  }
}
Module: @ember/routing

Available since v1.4.0

The name of the controller to associate with this route.

By default, Ember will lookup a route's controller that matches the name of the route (i.e. posts.new). However, if you would like to define a specific controller to use, you can do so using this property.

This is useful in many ways, as the controller specified will be:

  • passed to the setupController method.
  • used as the controller for the template being rendered by the route.
  • returned from a call to controllerFor for the route.
Module: @ember/routing

Available since v2.10.0

The name of the route, dot-delimited, including the engine prefix if applicable.

For example, a route found at addon/routes/posts/post.js within an engine named admin will have a fullRouteName of admin.posts.post.

Module: @ember/routing

Destroyed object property flag.

if this property is true the observers and bindings were already removed by the effect of calling the destroy() method.

Module: @ember/routing

Destruction scheduled flag. The destroy() method has been called.

The object stays intact until the end of the run loop at which point the isDestroyed flag is set.

Module: @ember/routing

Defines the properties that will be merged from the superclass (instead of overridden).

By default, when you extend an Ember class a property defined in the subclass overrides a property with the same name that is defined in the superclass. However, there are some cases where it is preferable to build up a property's value by merging the superclass property value with the subclass property's value. An example of this in use within Ember is the queryParams property of routes.

Here is some sample code showing the difference between a merged property and a normal one:

import EmberObject from '@ember/object';

const Bar = EmberObject.extend({
  // Configure which properties are to be merged
  mergedProperties: ['mergedProperty'],

  someNonMergedProperty: {
    nonMerged: 'superclass value of nonMerged'
  },
  mergedProperty: {
    page: { replace: false },
    limit: { replace: true }
  }
});

const FooBar = Bar.extend({
  someNonMergedProperty: {
    completelyNonMerged: 'subclass value of nonMerged'
  },
  mergedProperty: {
    limit: { replace: false }
  }
});

let fooBar = FooBar.create();

fooBar.get('someNonMergedProperty');
// => { completelyNonMerged: 'subclass value of nonMerged' }
//
// Note the entire object, including the nonMerged property of
// the superclass object, has been replaced

fooBar.get('mergedProperty');
// => {
//   page: {replace: false},
//   limit: {replace: false}
// }
//
// Note the page remains from the superclass, and the
// `limit` property's value of `false` has been merged from
// the subclass.

This behavior is not available during object create calls. It is only available at extend time.

In Route the queryParams property is merged.

This feature is available for you to use throughout the Ember object model, although typical app developers are likely to use it infrequently. Since it changes expectations about behavior of properties, you should properly document its usage in each individual merged property (to not mislead your users to think they can override the property in a subclass).

Module: @ember/routing

Available since v1.6.0

Configuration hash for this route's queryParams. The possible configuration options and their defaults are as follows (assuming a query param whose controller property is page):

queryParams: {
  page: {
    // By default, controller query param properties don't
    // cause a full transition when they are changed, but
    // rather only cause the URL to update. Setting
    // `refreshModel` to true will cause an "in-place"
    // transition to occur, whereby the model hooks for
    // this route (and any child routes) will re-fire, allowing
    // you to reload models (e.g., from the server) using the
    // updated query param values.
    refreshModel: false,

    // By default, changes to controller query param properties
    // cause the URL to update via `pushState`, which means an
    // item will be added to the browser's history, allowing
    // you to use the back button to restore the app to the
    // previous state before the query param property was changed.
    // Setting `replace` to true will use `replaceState` (or its
    // hash location equivalent), which causes no browser history
    // item to be added. This options name and default value are
    // the same as the `link-to` helper's `replace` option.
    replace: false,

    // By default, the query param URL key is the same name as
    // the controller property name. Use `as` to specify a
    // different URL key.
    as: 'page'
  }
}
Module: @ember/routing

Available since v1.0.0

The name of the route, dot-delimited.

For example, a route found at app/routes/posts/post.js will have a routeName of posts.post.

Module: @ember/routing

Available since v1.4.0

The name of the template to use by default when rendering this routes template.

app/routes/posts/list.js
import Route from '@ember/routing/route';

export default class extends Route {
  templateName = 'posts/list'
});
app/routes/posts/index.js
import PostsList from '../posts/list';

export default class extends PostsList {};
app/routes/posts/archived.js
import PostsList from '../posts/list';

export default class extends PostsList {};