Class RouterService
public
Extends:
Service
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 { 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
- addObserver
- cacheFor
- decrementProperty
- destroy
- get
- getProperties
- incrementProperty
- init
- isActive
- notifyPropertyChange
- off
- on
- recognize
- recognizeAndLoad
- refresh
- removeObserver
- replaceWith
- set
- setProperties
- toString
- toggleProperty
- transitionTo
- urlFor
- willDestroy
Properties
- concatenatedProperties
- currentRoute
- currentRouteName
- currentURL
- isDestroyed
- isDestroying
- location
- mergedProperties
- rootURL