Skip to content

Commit f8001db

Browse files
authored
Merge pull request #20359 from spuxx1701/route-docs-transition-to
2 parents badb84b + 0a1eb23 commit f8001db

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

packages/@ember/routing/route.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ interface Route<Model = unknown> extends IRoute<Model>, ActionHandler, Evented {
113113
```
114114
115115
You can also redirect elsewhere by calling
116-
`this.transitionTo('elsewhere')` from within `willTransition`.
116+
`this.router.transitionTo('elsewhere')` from within `willTransition`.
117117
Note that `willTransition` will not be fired for the
118118
redirecting `transitionTo`, since `willTransition` doesn't
119119
fire when there is already a transition underway. If you want
@@ -210,8 +210,11 @@ interface Route<Model = unknown> extends IRoute<Model>, ActionHandler, Evented {
210210
import { reject } from 'rsvp';
211211
import Route from '@ember/routing/route';
212212
import { action } from '@ember/object';
213+
import { service } from '@ember/service';
213214
214215
export default class AdminRoute extends Route {
216+
@service router;
217+
215218
beforeModel() {
216219
return reject('bad things!');
217220
}
@@ -228,7 +231,7 @@ interface Route<Model = unknown> extends IRoute<Model>, ActionHandler, Evented {
228231
// `transition`, which can be stored and later
229232
// `.retry()`d if desired.
230233
231-
this.transitionTo('login');
234+
this.router.transitionTo('login');
232235
}
233236
}
234237
```
@@ -1009,7 +1012,7 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
10091012
as a parameter, which can be used to `.abort()` the transition,
10101013
save it for a later `.retry()`, or retrieve values set
10111014
on it from a previous hook. You can also just call
1012-
`this.transitionTo` to another route to implicitly
1015+
`router.transitionTo` to another route to implicitly
10131016
abort the `transition`.
10141017
10151018
You can return a promise from this hook to pause the
@@ -1039,11 +1042,14 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
10391042
10401043
```app/routes/posts.js
10411044
import Route from '@ember/routing/route';
1045+
import { service } from '@ember/service';
10421046
10431047
export default class PostsRoute extends Route {
1048+
@service router;
1049+
10441050
afterModel(posts, transition) {
10451051
if (posts.get('length') === 1) {
1046-
this.transitionTo('post.show', posts.get('firstObject'));
1052+
this.router.transitionTo('post.show', posts.get('firstObject'));
10471053
}
10481054
}
10491055
}
@@ -1073,12 +1079,12 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
10731079
/**
10741080
A hook you can implement to optionally redirect to another route.
10751081
1076-
Calling `this.transitionTo` from inside of the `redirect` hook will
1082+
Calling `this.router.transitionTo` from inside of the `redirect` hook will
10771083
abort the current transition (into the route that has implemented `redirect`).
10781084
10791085
`redirect` and `afterModel` behave very similarly and are
10801086
called almost at the same time, but they have an important
1081-
distinction when calling `this.transitionTo` to a child route
1087+
distinction when calling `this.router.transitionTo` to a child route
10821088
of the current route. From `afterModel`, this new transition
10831089
invalidates the current transition, causing `beforeModel`,
10841090
`model`, and `afterModel` hooks to be called again. But the
@@ -1132,19 +1138,19 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
11321138
11331139
```javascript
11341140
// no dynamic segment, model hook always called
1135-
this.transitionTo('posts');
1141+
this.router.transitionTo('posts');
11361142
11371143
// model passed in, so model hook not called
11381144
thePost = store.findRecord('post', 1);
1139-
this.transitionTo('post', thePost);
1145+
this.router.transitionTo('post', thePost);
11401146
11411147
// integer passed in, model hook is called
1142-
this.transitionTo('post', 1);
1148+
this.router.transitionTo('post', 1);
11431149
11441150
// model id passed in, model hook is called
11451151
// useful for forcing the hook to execute
11461152
thePost = store.findRecord('post', 1);
1147-
this.transitionTo('post', thePost.id);
1153+
this.router.transitionTo('post', thePost.id);
11481154
```
11491155
11501156
This hook follows the asynchronous/promise semantics

0 commit comments

Comments
 (0)