@@ -113,7 +113,7 @@ interface Route<Model = unknown> extends IRoute<Model>, ActionHandler, Evented {
113
113
```
114
114
115
115
You can also redirect elsewhere by calling
116
- `this.transitionTo('elsewhere')` from within `willTransition`.
116
+ `this.router. transitionTo('elsewhere')` from within `willTransition`.
117
117
Note that `willTransition` will not be fired for the
118
118
redirecting `transitionTo`, since `willTransition` doesn't
119
119
fire when there is already a transition underway. If you want
@@ -210,8 +210,11 @@ interface Route<Model = unknown> extends IRoute<Model>, ActionHandler, Evented {
210
210
import { reject } from 'rsvp';
211
211
import Route from '@ember/routing/route';
212
212
import { action } from '@ember/object';
213
+ import { service } from '@ember/service';
213
214
214
215
export default class AdminRoute extends Route {
216
+ @service router;
217
+
215
218
beforeModel() {
216
219
return reject('bad things!');
217
220
}
@@ -228,7 +231,7 @@ interface Route<Model = unknown> extends IRoute<Model>, ActionHandler, Evented {
228
231
// `transition`, which can be stored and later
229
232
// `.retry()`d if desired.
230
233
231
- this.transitionTo('login');
234
+ this.router. transitionTo('login');
232
235
}
233
236
}
234
237
```
@@ -1009,7 +1012,7 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
1009
1012
as a parameter, which can be used to `.abort()` the transition,
1010
1013
save it for a later `.retry()`, or retrieve values set
1011
1014
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
1013
1016
abort the `transition`.
1014
1017
1015
1018
You can return a promise from this hook to pause the
@@ -1039,11 +1042,14 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
1039
1042
1040
1043
```app/routes/posts.js
1041
1044
import Route from '@ember/routing/route';
1045
+ import { service } from '@ember/service';
1042
1046
1043
1047
export default class PostsRoute extends Route {
1048
+ @service router;
1049
+
1044
1050
afterModel(posts, transition) {
1045
1051
if (posts.get('length') === 1) {
1046
- this.transitionTo('post.show', posts.get('firstObject'));
1052
+ this.router. transitionTo('post.show', posts.get('firstObject'));
1047
1053
}
1048
1054
}
1049
1055
}
@@ -1073,12 +1079,12 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
1073
1079
/**
1074
1080
A hook you can implement to optionally redirect to another route.
1075
1081
1076
- Calling `this.transitionTo` from inside of the `redirect` hook will
1082
+ Calling `this.router. transitionTo` from inside of the `redirect` hook will
1077
1083
abort the current transition (into the route that has implemented `redirect`).
1078
1084
1079
1085
`redirect` and `afterModel` behave very similarly and are
1080
1086
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
1082
1088
of the current route. From `afterModel`, this new transition
1083
1089
invalidates the current transition, causing `beforeModel`,
1084
1090
`model`, and `afterModel` hooks to be called again. But the
@@ -1132,19 +1138,19 @@ class Route<Model = unknown> extends EmberObject.extend(ActionHandler, Evented)
1132
1138
1133
1139
```javascript
1134
1140
// no dynamic segment, model hook always called
1135
- this.transitionTo('posts');
1141
+ this.router. transitionTo('posts');
1136
1142
1137
1143
// model passed in, so model hook not called
1138
1144
thePost = store.findRecord('post', 1);
1139
- this.transitionTo('post', thePost);
1145
+ this.router. transitionTo('post', thePost);
1140
1146
1141
1147
// integer passed in, model hook is called
1142
- this.transitionTo('post', 1);
1148
+ this.router. transitionTo('post', 1);
1143
1149
1144
1150
// model id passed in, model hook is called
1145
1151
// useful for forcing the hook to execute
1146
1152
thePost = store.findRecord('post', 1);
1147
- this.transitionTo('post', thePost.id);
1153
+ this.router. transitionTo('post', thePost.id);
1148
1154
```
1149
1155
1150
1156
This hook follows the asynchronous/promise semantics
0 commit comments