Skip to content

Commit

Permalink
Merge pull request #20359 from spuxx1701/route-docs-transition-to
Browse files Browse the repository at this point in the history
  • Loading branch information
kategengler authored Aug 29, 2023
2 parents badb84b + 0a1eb23 commit f8001db
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions packages/@ember/routing/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ interface Route<Model = unknown> extends IRoute<Model>, ActionHandler, Evented {
```
You can also redirect elsewhere by calling
`this.transitionTo('elsewhere')` from within `willTransition`.
`this.router.transitionTo('elsewhere')` from within `willTransition`.
Note that `willTransition` will not be fired for the
redirecting `transitionTo`, since `willTransition` doesn't
fire when there is already a transition underway. If you want
Expand Down Expand Up @@ -210,8 +210,11 @@ interface Route<Model = unknown> extends IRoute<Model>, ActionHandler, Evented {
import { reject } from 'rsvp';
import Route from '@ember/routing/route';
import { action } from '@ember/object';
import { service } from '@ember/service';
export default class AdminRoute extends Route {
@service router;
beforeModel() {
return reject('bad things!');
}
Expand All @@ -228,7 +231,7 @@ interface Route<Model = unknown> extends IRoute<Model>, ActionHandler, Evented {
// `transition`, which can be stored and later
// `.retry()`d if desired.
this.transitionTo('login');
this.router.transitionTo('login');
}
}
```
Expand Down Expand Up @@ -1009,7 +1012,7 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
as a parameter, which can be used to `.abort()` the transition,
save it for a later `.retry()`, or retrieve values set
on it from a previous hook. You can also just call
`this.transitionTo` to another route to implicitly
`router.transitionTo` to another route to implicitly
abort the `transition`.
You can return a promise from this hook to pause the
Expand Down Expand Up @@ -1039,11 +1042,14 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
```app/routes/posts.js
import Route from '@ember/routing/route';
import { service } from '@ember/service';
export default class PostsRoute extends Route {
@service router;
afterModel(posts, transition) {
if (posts.get('length') === 1) {
this.transitionTo('post.show', posts.get('firstObject'));
this.router.transitionTo('post.show', posts.get('firstObject'));
}
}
}
Expand Down Expand Up @@ -1073,12 +1079,12 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
/**
A hook you can implement to optionally redirect to another route.
Calling `this.transitionTo` from inside of the `redirect` hook will
Calling `this.router.transitionTo` from inside of the `redirect` hook will
abort the current transition (into the route that has implemented `redirect`).
`redirect` and `afterModel` behave very similarly and are
called almost at the same time, but they have an important
distinction when calling `this.transitionTo` to a child route
distinction when calling `this.router.transitionTo` to a child route
of the current route. From `afterModel`, this new transition
invalidates the current transition, causing `beforeModel`,
`model`, and `afterModel` hooks to be called again. But the
Expand Down Expand Up @@ -1132,19 +1138,19 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
```javascript
// no dynamic segment, model hook always called
this.transitionTo('posts');
this.router.transitionTo('posts');
// model passed in, so model hook not called
thePost = store.findRecord('post', 1);
this.transitionTo('post', thePost);
this.router.transitionTo('post', thePost);
// integer passed in, model hook is called
this.transitionTo('post', 1);
this.router.transitionTo('post', 1);
// model id passed in, model hook is called
// useful for forcing the hook to execute
thePost = store.findRecord('post', 1);
this.transitionTo('post', thePost.id);
this.router.transitionTo('post', thePost.id);
```
This hook follows the asynchronous/promise semantics
Expand Down

0 comments on commit f8001db

Please sign in to comment.