Class RouterService

public
Extends: Service
Defined in: packages/@ember/-internals/routing/lib/services/router.ts:37
Module: @ember/routing

The Router service is the public API that provides access to the router.

The immediate benefit of the Router service is that you can inject it into components, giving them a friendly way to initiate transitions and ask questions about the current global router state.

In this example, the Router service is injected into a component to initiate a transition to a dedicated route:

app/components/example.js
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';

export default class ExampleComponent extends Component {
  @service router;

  @action
  next() {
    this.router.transitionTo('other.route');
  }
}

Like any service, it can also be injected into helpers, routes, etc.

Methods

Properties

Events

© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/classes/RouterService