-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
route.ts
2664 lines (2185 loc) · 74.6 KB
/
route.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { OwnedTemplate, TemplateFactory } from '@ember/-internals/glimmer';
import {
addObserver,
computed,
defineProperty,
descriptorForProperty,
flushAsyncObservers,
get,
getProperties,
isEmpty,
set,
setProperties,
} from '@ember/-internals/metal';
import { getOwner, Owner } from '@ember/-internals/owner';
import {
A as emberA,
ActionHandler,
Evented,
Object as EmberObject,
setFrameworkClass,
typeOf,
} from '@ember/-internals/runtime';
import { lookupDescriptor } from '@ember/-internals/utils';
import Controller from '@ember/controller';
import { assert, deprecate, info, isTesting } from '@ember/debug';
import { ROUTER_EVENTS } from '@ember/deprecated-features';
import { dependentKeyCompat } from '@ember/object/compat';
import { assign } from '@ember/polyfills';
import { once } from '@ember/runloop';
import { classify } from '@ember/string';
import { DEBUG } from '@glimmer/env';
import {
InternalRouteInfo,
PARAMS_SYMBOL,
Route as IRoute,
STATE_SYMBOL,
Transition,
TransitionState,
} from 'router_js';
import {
calculateCacheKey,
normalizeControllerQueryParams,
prefixRouteNameArg,
stashParamNames,
} from '../utils';
import generateController from './generate_controller';
import EmberRouter, { QueryParam } from './router';
export const ROUTE_CONNECTIONS = new WeakMap();
export function defaultSerialize(model: {}, params: string[]) {
if (params.length < 1 || !model) {
return;
}
let object = {};
if (params.length === 1) {
let [name] = params;
if (name in model) {
object[name] = get(model, name);
} else if (/_id$/.test(name)) {
object[name] = get(model, 'id');
}
} else {
object = getProperties(model, params);
}
return object;
}
export function hasDefaultSerialize(route: Route) {
return route.serialize === defaultSerialize;
}
/**
@module @ember/routing
*/
/**
The `Route` class is used to define individual routes. Refer to
the [routing guide](https://guides.emberjs.com/release/routing/) for documentation.
@class Route
@extends EmberObject
@uses ActionHandler
@uses Evented
@since 1.0.0
@public
*/
class Route extends EmberObject implements IRoute {
routeName!: string;
fullRouteName!: string;
context: {} = {};
controller!: Controller;
currentModel: unknown;
_internalName!: string;
_names: unknown;
serialize!: (model: {}, params: string[]) => object | undefined;
_router!: EmberRouter;
/**
The name of the route, dot-delimited.
For example, a route found at `app/routes/posts/post.js` will have
a `routeName` of `posts.post`.
@property routeName
@for Route
@type String
@since 1.0.0
@public
*/
/**
The name of the route, dot-delimited, including the engine prefix
if applicable.
For example, a route found at `addon/routes/posts/post.js` within an
engine named `admin` will have a `fullRouteName` of `admin.posts.post`.
@property fullRouteName
@for Route
@type String
@since 2.10.0
@public
*/
/**
Sets the name for this route, including a fully resolved name for routes
inside engines.
@private
@method _setRouteName
@param {String} name
*/
_setRouteName(name: string) {
this.routeName = name;
this.fullRouteName = getEngineRouteName(getOwner(this), name)!;
}
/**
@private
@method _stashNames
*/
_stashNames(routeInfo: InternalRouteInfo<this>, dynamicParent: InternalRouteInfo<this>) {
if (this._names) {
return;
}
let names = (this._names = routeInfo['_names']);
if (!names.length) {
routeInfo = dynamicParent;
names = (routeInfo && routeInfo['_names']) || [];
}
let qps = get(this, '_qp.qps');
let namePaths = new Array(names.length);
for (let a = 0; a < names.length; ++a) {
namePaths[a] = `${routeInfo.name}.${names[a]}`;
}
for (let i = 0; i < qps.length; ++i) {
let qp = qps[i];
if (qp.scope === 'model') {
qp.parts = namePaths;
}
}
}
/**
@private
@property _activeQPChanged
*/
_activeQPChanged(qp: QueryParam, value: unknown) {
this._router._activeQPChanged(qp.scopedPropertyName, value);
}
/**
@private
@method _updatingQPChanged
*/
_updatingQPChanged(qp: QueryParam) {
this._router._updatingQPChanged(qp.urlKey);
}
/**
Returns a hash containing the parameters of an ancestor route.
You may notice that `this.paramsFor` sometimes works when referring to a
child route, but this behavior should not be relied upon as only ancestor
routes are certain to be loaded in time.
Example
```app/router.js
// ...
Router.map(function() {
this.route('member', { path: ':name' }, function() {
this.route('interest', { path: ':interest' });
});
});
```
```app/routes/member.js
import Route from '@ember/routing/route';
export default class MemberRoute extends Route {
queryParams = {
memberQp: { refreshModel: true }
}
}
```
```app/routes/member/interest.js
import Route from '@ember/routing/route';
export default class MemberInterestRoute Route {
queryParams = {
interestQp: { refreshModel: true }
}
model() {
return this.paramsFor('member');
}
}
```
If we visit `/turing/maths?memberQp=member&interestQp=interest` the model for
the `member.interest` route is a hash with:
* `name`: `turing`
* `memberQp`: `member`
@method paramsFor
@param {String} name
@return {Object} hash containing the parameters of the route `name`
@since 1.4.0
@public
*/
paramsFor(name: string) {
let route = getOwner(this).lookup<Route>(`route:${name}`);
if (route === undefined) {
return {};
}
let transition = this._router._routerMicrolib.activeTransition;
let state = transition ? transition[STATE_SYMBOL] : this._router._routerMicrolib.state;
let fullName = route.fullRouteName;
let params = assign({}, state!.params[fullName!]);
let queryParams = getQueryParamsFor(route, state!);
return Object.keys(queryParams).reduce((params, key) => {
assert(
`The route '${this.routeName}' has both a dynamic segment and query param with name '${key}'. Please rename one to avoid collisions.`,
!params[key]
);
params[key] = queryParams[key];
return params;
}, params);
}
/**
Serializes the query parameter key
@method serializeQueryParamKey
@param {String} controllerPropertyName
@private
*/
serializeQueryParamKey(controllerPropertyName: string) {
return controllerPropertyName;
}
/**
Serializes value of the query parameter based on defaultValueType
@method serializeQueryParam
@param {Object} value
@param {String} urlKey
@param {String} defaultValueType
@private
*/
serializeQueryParam(value: unknown, _urlKey: string, defaultValueType: string) {
// urlKey isn't used here, but anyone overriding
// can use it to provide serialization specific
// to a certain query param.
return this._router._serializeQueryParam(value, defaultValueType);
}
/**
Deserializes value of the query parameter based on defaultValueType
@method deserializeQueryParam
@param {Object} value
@param {String} urlKey
@param {String} defaultValueType
@private
*/
deserializeQueryParam(value: unknown, _urlKey: string, defaultValueType: string) {
// urlKey isn't used here, but anyone overriding
// can use it to provide deserialization specific
// to a certain query param.
return this._router._deserializeQueryParam(value, defaultValueType);
}
/**
@private
@property _optionsForQueryParam
*/
_optionsForQueryParam(qp: QueryParam) {
return get(this, `queryParams.${qp.urlKey}`) || get(this, `queryParams.${qp.prop}`) || {};
}
/**
A hook you can use to reset controller values either when the model
changes or the route is exiting.
```app/routes/articles.js
import Route from '@ember/routing/route';
export default class ArticlesRoute extends Route {
resetController(controller, isExiting, transition) {
if (isExiting && transition.targetName !== 'error') {
controller.set('page', 1);
}
}
}
```
@method resetController
@param {Controller} controller instance
@param {Boolean} isExiting
@param {Object} transition
@since 1.7.0
@public
*/
resetController(_controller: any, _isExiting: boolean, _transition: Transition) {
return this;
}
/**
@private
@method exit
*/
exit() {
this.deactivate();
this.trigger('deactivate');
this.teardownViews();
}
/**
@private
@method _internalReset
@since 3.6.0
*/
_internalReset(isExiting: boolean, transition: Transition) {
let controller = this.controller;
controller['_qpDelegate'] = get(this, '_qp.states.inactive');
this.resetController(controller, isExiting, transition);
}
/**
@private
@method enter
*/
enter() {
ROUTE_CONNECTIONS.set(this, []);
this.activate();
this.trigger('activate');
}
/**
The `willTransition` action is fired at the beginning of any
attempted transition with a `Transition` object as the sole
argument. This action can be used for aborting, redirecting,
or decorating the transition from the currently active routes.
A good example is preventing navigation when a form is
half-filled out:
```app/routes/contact-form.js
import Route from '@ember/routing/route';
import { action } from '@ember/object';
export default class ContactFormRoute extends Route {
@action
willTransition(transition) {
if (this.controller.get('userHasEnteredData')) {
this.controller.displayNavigationConfirm();
transition.abort();
}
}
}
```
You can also redirect elsewhere by calling
`this.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
subsequent `willTransition` actions to fire for the redirecting
transition, you must first explicitly call
`transition.abort()`.
To allow the `willTransition` event to continue bubbling to the parent
route, use `return true;`. When the `willTransition` method has a
return value of `true` then the parent route's `willTransition` method
will be fired, enabling "bubbling" behavior for the event.
@event willTransition
@param {Transition} transition
@since 1.0.0
@public
*/
/**
The `didTransition` action is fired after a transition has
successfully been completed. This occurs after the normal model
hooks (`beforeModel`, `model`, `afterModel`, `setupController`)
have resolved. The `didTransition` action has no arguments,
however, it can be useful for tracking page views or resetting
state on the controller.
```app/routes/login.js
import Route from '@ember/routing/route';
import { action } from '@ember/object';
export default class LoginRoute extends Route {
@action
didTransition() {
this.controller.get('errors.base').clear();
return true; // Bubble the didTransition event
}
}
```
@event didTransition
@since 1.2.0
@public
*/
/**
The `loading` action is fired on the route when a route's `model`
hook returns a promise that is not already resolved. The current
`Transition` object is the first parameter and the route that
triggered the loading event is the second parameter.
```app/routes/application.js
import Route from '@ember/routing/route';
import { action } from '@ember/object';
export default class ApplicationRoute extends Route {
@action
loading(transition, route) {
let controller = this.controllerFor('foo');
controller.set('currentlyLoading', true);
transition.finally(function() {
controller.set('currentlyLoading', false);
});
}
}
```
@event loading
@param {Transition} transition
@param {Route} route The route that triggered the loading event
@since 1.2.0
@public
*/
/**
When attempting to transition into a route, any of the hooks
may return a promise that rejects, at which point an `error`
action will be fired on the partially-entered routes, allowing
for per-route error handling logic, or shared error handling
logic defined on a parent route.
Here is an example of an error handler that will be invoked
for rejected promises from the various hooks on the route,
as well as any unhandled errors from child routes:
```app/routes/admin.js
import { reject } from 'rsvp';
import Route from '@ember/routing/route';
import { action } from '@ember/object';
export default class AdminRoute extends Route {
beforeModel() {
return reject('bad things!');
}
@action
error(error, transition) {
// Assuming we got here due to the error in `beforeModel`,
// we can expect that error === "bad things!",
// but a promise model rejecting would also
// call this hook, as would any errors encountered
// in `afterModel`.
// The `error` hook is also provided the failed
// `transition`, which can be stored and later
// `.retry()`d if desired.
this.transitionTo('login');
}
}
```
`error` actions that bubble up all the way to `ApplicationRoute`
will fire a default error handler that logs the error. You can
specify your own global default error handler by overriding the
`error` handler on `ApplicationRoute`:
```app/routes/application.js
import Route from '@ember/routing/route';
import { action } from '@ember/object';
export default class ApplicationRoute extends Route {
@action
error(error, transition) {
this.controllerFor('banner').displayError(error.message);
}
}
```
@event error
@param {Error} error
@param {Transition} transition
@since 1.0.0
@public
*/
/**
This event is triggered when the router enters the route. It is
not executed when the model for the route changes.
```app/routes/application.js
import { on } from '@ember/object/evented';
import Route from '@ember/routing/route';
export default Route.extend({
collectAnalytics: on('activate', function(){
collectAnalytics();
})
});
```
@event activate
@since 1.9.0
@public
*/
/**
This event is triggered when the router completely exits this
route. It is not executed when the model for the route changes.
```app/routes/index.js
import { on } from '@ember/object/evented';
import Route from '@ember/routing/route';
export default Route.extend({
trackPageLeaveAnalytics: on('deactivate', function(){
trackPageLeaveAnalytics();
})
});
```
@event deactivate
@since 1.9.0
@public
*/
/**
This hook is executed when the router completely exits this route. It is
not executed when the model for the route changes.
@method deactivate
@since 1.0.0
@public
*/
deactivate() {}
/**
This hook is executed when the router enters the route. It is not executed
when the model for the route changes.
@method activate
@since 1.0.0
@public
*/
activate() {}
/**
Transition the application into another route. The route may
be either a single route or route path:
```javascript
this.transitionTo('blogPosts');
this.transitionTo('blogPosts.recentEntries');
```
Optionally supply a model for the route in question. The model
will be serialized into the URL using the `serialize` hook of
the route:
```javascript
this.transitionTo('blogPost', aPost);
```
If a literal is passed (such as a number or a string), it will
be treated as an identifier instead. In this case, the `model`
hook of the route will be triggered:
```javascript
this.transitionTo('blogPost', 1);
```
Multiple models will be applied last to first recursively up the
route tree.
```app/routes.js
// ...
Router.map(function() {
this.route('blogPost', { path:':blogPostId' }, function() {
this.route('blogComment', { path: ':blogCommentId' });
});
});
export default Router;
```
```javascript
this.transitionTo('blogComment', aPost, aComment);
this.transitionTo('blogComment', 1, 13);
```
It is also possible to pass a URL (a string that starts with a
`/`).
```javascript
this.transitionTo('/');
this.transitionTo('/blog/post/1/comment/13');
this.transitionTo('/blog/posts?sort=title');
```
An options hash with a `queryParams` property may be provided as
the final argument to add query parameters to the destination URL.
```javascript
this.transitionTo('blogPost', 1, {
queryParams: { showComments: 'true' }
});
// if you just want to transition the query parameters without changing the route
this.transitionTo({ queryParams: { sort: 'date' } });
```
See also [replaceWith](#method_replaceWith).
Simple Transition Example
```app/routes.js
// ...
Router.map(function() {
this.route('index');
this.route('secret');
this.route('fourOhFour', { path: '*:' });
});
export default Router;
```
```app/routes/index.js
import Route from '@ember/routing/route';
import { action } from '@ember/object';
export default class IndexRoute extends Route {
@action
moveToSecret(context) {
if (authorized()) {
this.transitionTo('secret', context);
} else {
this.transitionTo('fourOhFour');
}
}
}
```
Transition to a nested route
```app/router.js
// ...
Router.map(function() {
this.route('articles', { path: '/articles' }, function() {
this.route('new');
});
});
export default Router;
```
```app/routes/index.js
import Route from '@ember/routing/route';
import { action } from '@ember/object';
export default class IndexRoute extends Route {
@action
transitionToNewArticle() {
this.transitionTo('articles.new');
}
}
```
Multiple Models Example
```app/router.js
// ...
Router.map(function() {
this.route('index');
this.route('breakfast', { path: ':breakfastId' }, function() {
this.route('cereal', { path: ':cerealId' });
});
});
export default Router;
```
```app/routes/index.js
import Route from '@ember/routing/route';
import { action } from '@ember/object';
export default class IndexRoute extends Route {
@action
moveToChocolateCereal() {
let cereal = { cerealId: 'ChocolateYumminess' };
let breakfast = { breakfastId: 'CerealAndMilk' };
this.transitionTo('breakfast.cereal', breakfast, cereal);
}
}
```
Nested Route with Query String Example
```app/routes.js
// ...
Router.map(function() {
this.route('fruits', function() {
this.route('apples');
});
});
export default Router;
```
```app/routes/index.js
import Route from '@ember/routing/route';
export default class IndexRoute extends Route {
@action
transitionToApples() {
this.transitionTo('fruits.apples', { queryParams: { color: 'red' } });
}
}
```
@method transitionTo
@param {String} name the name of the route or a URL
@param {...Object} models the model(s) or identifier(s) to be used while
transitioning to the route.
@param {Object} [options] optional hash with a queryParams property
containing a mapping of query parameters
@return {Transition} the transition object associated with this
attempted transition
@since 1.0.0
@public
*/
transitionTo(...args: any[]) {
// eslint-disable-line no-unused-vars
return this._router.transitionTo(...prefixRouteNameArg(this, args));
}
/**
Perform a synchronous transition into another route without attempting
to resolve promises, update the URL, or abort any currently active
asynchronous transitions (i.e. regular transitions caused by
`transitionTo` or URL changes).
This method is handy for performing intermediate transitions on the
way to a final destination route, and is called internally by the
default implementations of the `error` and `loading` handlers.
@method intermediateTransitionTo
@param {String} name the name of the route
@param {...Object} models the model(s) to be used while transitioning
to the route.
@since 1.2.0
@public
*/
intermediateTransitionTo(...args: any[]) {
let [name, ...preparedArgs] = prefixRouteNameArg(this, args);
this._router.intermediateTransitionTo(name, ...preparedArgs);
}
/**
Refresh the model on this route and any child routes, firing the
`beforeModel`, `model`, and `afterModel` hooks in a similar fashion
to how routes are entered when transitioning in from other route.
The current route params (e.g. `article_id`) will be passed in
to the respective model hooks, and if a different model is returned,
`setupController` and associated route hooks will re-fire as well.
An example usage of this method is re-querying the server for the
latest information using the same parameters as when the route
was first entered.
Note that this will cause `model` hooks to fire even on routes
that were provided a model object when the route was initially
entered.
@method refresh
@return {Transition} the transition object associated with this
attempted transition
@since 1.4.0
@public
*/
refresh() {
return this._router._routerMicrolib.refresh(this);
}
/**
Transition into another route while replacing the current URL, if possible.
This will replace the current history entry instead of adding a new one.
Beside that, it is identical to `transitionTo` in all other respects. See
'transitionTo' for additional information regarding multiple models.
Example
```app/router.js
// ...
Router.map(function() {
this.route('index');
this.route('secret');
});
export default Router;
```
```app/routes/secret.js
import Route from '@ember/routing/route';
export default class SecretRoute Route {
afterModel() {
if (!authorized()){
this.replaceWith('index');
}
}
}
```
@method replaceWith
@param {String} name the name of the route or a URL
@param {...Object} models the model(s) or identifier(s) to be used while
transitioning to the route.
@param {Object} [options] optional hash with a queryParams property
containing a mapping of query parameters
@return {Transition} the transition object associated with this
attempted transition
@since 1.0.0
@public
*/
replaceWith(...args: any[]) {
return this._router.replaceWith(...prefixRouteNameArg(this, args));
}
/**
This hook is the entry point for router.js
@private
@method setup
*/
setup(context: {}, transition: Transition) {
let controllerName = this.controllerName || this.routeName;
let definedController = this.controllerFor(controllerName, true);
let controller: any;
if (definedController) {
controller = definedController;
} else {
controller = this.generateController(controllerName);
}
// Assign the route's controller so that it can more easily be
// referenced in action handlers. Side effects. Side effects everywhere.
if (!this.controller) {
let qp = get(this, '_qp');
let propNames = qp !== undefined ? get(qp, 'propertyNames') : [];
addQueryParamsObservers(controller, propNames);
this.controller = controller;
}
let queryParams = get(this, '_qp');
let states = queryParams.states;
controller._qpDelegate = states.allowOverrides;
if (transition) {
// Update the model dep values used to calculate cache keys.
stashParamNames(this._router, transition[STATE_SYMBOL]!.routeInfos);
let cache = this._bucketCache;
let params = transition[PARAMS_SYMBOL];
let allParams = queryParams.propertyNames;
allParams.forEach((prop: string) => {
let aQp = queryParams.map[prop];
aQp.values = params;
let cacheKey = calculateCacheKey(aQp.route.fullRouteName, aQp.parts, aQp.values);
let value = cache.lookup(cacheKey, prop, aQp.undecoratedDefaultValue);
set(controller, prop, value);
});
let qpValues = getQueryParamsFor(this, transition[STATE_SYMBOL]!);
setProperties(controller, qpValues);
}
this.setupController(controller, context, transition);
if (this._environment.options.shouldRender) {
this.renderTemplate(controller, context);
}
// Setup can cause changes to QPs which need to be propogated immediately in
// some situations. Eventually, we should work on making these async somehow.
flushAsyncObservers(false);
}
/*
Called when a query parameter for this route changes, regardless of whether the route
is currently part of the active route hierarchy. This will update the query parameter's
value in the cache so if this route becomes active, the cache value has been updated.
*/
_qpChanged(prop: string, value: unknown, qp: QueryParam) {
if (!qp) {
return;
}
// Update model-dep cache
let cache = this._bucketCache;
let cacheKey = calculateCacheKey(qp.route.fullRouteName, qp.parts, qp.values);
cache.stash(cacheKey, prop, value);
}
/**
This hook is the first of the route entry validation hooks
called when an attempt is made to transition into a route
or one of its children. It is called before `model` and
`afterModel`, and is appropriate for cases when:
1) A decision can be made to redirect elsewhere without
needing to resolve the model first.
2) Any async operations need to occur first before the
model is attempted to be resolved.
This hook is provided the current `transition` attempt
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
abort the `transition`.
You can return a promise from this hook to pause the
transition until the promise resolves (or rejects). This could
be useful, for instance, for retrieving async code from
the server that is required to enter a route.
@method beforeModel