-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathroute.js
2108 lines (1747 loc) · 60.3 KB
/
route.js
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 Ember from "ember-metal/core"; // FEATURES, A, deprecate, assert, Logger
import EmberError from "ember-metal/error";
import { get } from "ember-metal/property_get";
import { set } from "ember-metal/property_set";
import getProperties from "ember-metal/get_properties";
import { forEach } from "ember-metal/enumerable_utils";
import isNone from "ember-metal/is_none";
import { computed } from "ember-metal/computed";
import merge from "ember-metal/merge";
import {
isArray,
typeOf
} from "ember-runtime/utils";
import run from "ember-metal/run_loop";
import keys from "ember-metal/keys";
import copy from "ember-runtime/copy";
import {
classify
} from "ember-runtime/system/string";
import EmberObject from "ember-runtime/system/object";
import Evented from "ember-runtime/mixins/evented";
import ActionHandler from "ember-runtime/mixins/action_handler";
import generateController from "ember-routing/system/generate_controller";
import { stashParamNames } from "ember-routing/utils";
var slice = Array.prototype.slice;
function K() { return this; }
/**
@module ember
@submodule ember-routing
*/
/**
The `Ember.Route` class is used to define individual routes. Refer to
the [routing guide](http://emberjs.com/guides/routing/) for documentation.
@class Route
@namespace Ember
@extends Ember.Object
@uses Ember.ActionHandler
@uses Ember.Evented
@public
*/
var Route = EmberObject.extend(ActionHandler, Evented, {
/**
Configuration hash for this route's queryParams. The possible
configuration options and their defaults are as follows
(assuming a query param whose controller property is `page`):
```javascript
queryParams: {
page: {
// By default, controller query param properties don't
// cause a full transition when they are changed, but
// rather only cause the URL to update. Setting
// `refreshModel` to true will cause an "in-place"
// transition to occur, whereby the model hooks for
// this route (and any child routes) will re-fire, allowing
// you to reload models (e.g., from the server) using the
// updated query param values.
refreshModel: false,
// By default, changes to controller query param properties
// cause the URL to update via `pushState`, which means an
// item will be added to the browser's history, allowing
// you to use the back button to restore the app to the
// previous state before the query param property was changed.
// Setting `replace` to true will use `replaceState` (or its
// hash location equivalent), which causes no browser history
// item to be added. This options name and default value are
// the same as the `link-to` helper's `replace` option.
replace: false,
// By default, the query param URL key is the same name as
// the controller property name. Use `as` to specify a
// different URL key.
as: 'page'
}
}
```
@property queryParams
@for Ember.Route
@type Object
@public
*/
queryParams: {},
/**
@private
@property _qp
*/
_qp: computed(function() {
var controllerName = this.controllerName || this.routeName;
var controllerClass = this.container.lookupFactory(`controller:${controllerName}`);
if (!controllerClass) {
return defaultQPMeta;
}
var controllerProto = controllerClass.proto();
var qpProps = get(controllerProto, '_normalizedQueryParams');
var cacheMeta = get(controllerProto, '_cacheMeta');
var qps = [];
var map = {};
for (var propName in qpProps) {
if (!qpProps.hasOwnProperty(propName)) { continue; }
var desc = qpProps[propName];
var urlKey = desc.as || this.serializeQueryParamKey(propName);
var defaultValue = get(controllerProto, propName);
if (isArray(defaultValue)) {
defaultValue = Ember.A(defaultValue.slice());
}
var type = typeOf(defaultValue);
var defaultValueSerialized = this.serializeQueryParam(defaultValue, urlKey, type);
var fprop = `${controllerName}:${propName}`;
var qp = {
def: defaultValue,
sdef: defaultValueSerialized,
type: type,
urlKey: urlKey,
prop: propName,
fprop: fprop,
ctrl: controllerName,
cProto: controllerProto,
svalue: defaultValueSerialized,
cacheType: desc.scope,
route: this,
cacheMeta: cacheMeta[propName]
};
map[propName] = map[urlKey] = map[fprop] = qp;
qps.push(qp);
}
return {
qps: qps,
map: map,
states: {
active: (controller, prop) => {
return this._activeQPChanged(controller, map[prop]);
},
allowOverrides: (controller, prop) => {
return this._updatingQPChanged(controller, map[prop]);
}
}
};
}),
/**
@private
@property _names
*/
_names: null,
/**
@private
@method _stashNames
*/
_stashNames(_handlerInfo, dynamicParent) {
var handlerInfo = _handlerInfo;
if (this._names) { return; }
var names = this._names = handlerInfo._names;
if (!names.length) {
handlerInfo = dynamicParent;
names = handlerInfo && handlerInfo._names || [];
}
var qps = get(this, '_qp.qps');
var len = qps.length;
var namePaths = new Array(names.length);
for (var a = 0, nlen = names.length; a < nlen; ++a) {
namePaths[a] = `${handlerInfo.name}.${names[a]}`;
}
for (var i = 0; i < len; ++i) {
var qp = qps[i];
var cacheMeta = qp.cacheMeta;
if (cacheMeta.scope === 'model') {
cacheMeta.parts = namePaths;
}
cacheMeta.prefix = qp.ctrl;
}
},
/**
@private
@property _updateSerializedQPValue
*/
_updateSerializedQPValue(controller, qp) {
var value = get(controller, qp.prop);
qp.svalue = this.serializeQueryParam(value, qp.urlKey, qp.type);
},
/**
@private
@property _activeQPChanged
*/
_activeQPChanged(controller, qp) {
var value = get(controller, qp.prop);
this.router._queuedQPChanges[qp.fprop] = value;
run.once(this, this._fireQueryParamTransition);
},
/**
@private
@method _updatingQPChanged
*/
_updatingQPChanged(controller, qp) {
var router = this.router;
if (!router._qpUpdates) {
router._qpUpdates = {};
}
router._qpUpdates[qp.urlKey] = true;
},
mergedProperties: ['events', 'queryParams'],
/**
Retrieves parameters, for current route using the state.params
variable and getQueryParamsFor, using the supplied routeName.
@method paramsFor
@param {String} name
@public
*/
paramsFor(name) {
var route = this.container.lookup(`route:${name}`);
if (!route) {
return {};
}
var transition = this.router.router.activeTransition;
var state = transition ? transition.state : this.router.router.state;
var params = {};
merge(params, state.params[name]);
merge(params, getQueryParamsFor(route, state));
return params;
},
/**
Serializes the query parameter key
@method serializeQueryParamKey
@param {String} controllerPropertyName
@private
*/
serializeQueryParamKey(controllerPropertyName) {
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, urlKey, defaultValueType) {
// urlKey isn't used here, but anyone overriding
// can use it to provide serialization specific
// to a certain query param.
if (defaultValueType === 'array') {
return JSON.stringify(value);
}
return `${value}`;
},
/**
Deserializes value of the query parameter based on defaultValueType
@method deserializeQueryParam
@param {Object} value
@param {String} urlKey
@param {String} defaultValueType
@private
*/
deserializeQueryParam(value, urlKey, defaultValueType) {
// urlKey isn't used here, but anyone overriding
// can use it to provide deserialization specific
// to a certain query param.
// Use the defaultValueType of the default value (the initial value assigned to a
// controller query param property), to intelligently deserialize and cast.
if (defaultValueType === 'boolean') {
return (value === 'true') ? true : false;
} else if (defaultValueType === 'number') {
return (Number(value)).valueOf();
} else if (defaultValueType === 'array') {
return Ember.A(JSON.parse(value));
}
return value;
},
/**
@private
@property _fireQueryParamTransition
*/
_fireQueryParamTransition() {
this.transitionTo({ queryParams: this.router._queuedQPChanges });
this.router._queuedQPChanges = {};
},
/**
@private
@property _optionsForQueryParam
*/
_optionsForQueryParam(qp) {
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.
```javascript
App.ArticlesRoute = Ember.Route.extend({
// ...
resetController: function (controller, isExiting, transition) {
if (isExiting) {
controller.set('page', 1);
}
}
});
```
@method resetController
@param {Controller} controller instance
@param {Boolean} isExiting
@param {Object} transition
@since 1.7.0
@public
*/
resetController: K,
/**
@private
@method exit
*/
exit() {
this.deactivate();
this.trigger('deactivate');
this.teardownViews();
},
/**
@private
@method _reset
@since 1.7.0
*/
_reset(isExiting, transition) {
var controller = this.controller;
controller._qpDelegate = null;
this.resetController(controller, isExiting, transition);
},
/**
@private
@method enter
*/
enter() {
this.connections = [];
this.activate();
this.trigger('activate');
},
/**
The name of the view to use by default when rendering this routes template.
When rendering a template, the route will, by default, determine the
template and view to use from the name of the route itself. If you need to
define a specific view, set this property.
This is useful when multiple routes would benefit from using the same view
because it doesn't require a custom `renderTemplate` method. For example,
the following routes will all render using the `App.PostsListView` view:
```javascript
var PostsList = Ember.Route.extend({
viewName: 'postsList'
});
App.PostsIndexRoute = PostsList.extend();
App.PostsArchivedRoute = PostsList.extend();
```
@property viewName
@type String
@default null
@since 1.4.0
@public
*/
viewName: null,
/**
The name of the template to use by default when rendering this routes
template.
This is similar with `viewName`, but is useful when you just want a custom
template without a view.
```javascript
var PostsList = Ember.Route.extend({
templateName: 'posts/list'
});
App.PostsIndexRoute = PostsList.extend();
App.PostsArchivedRoute = PostsList.extend();
```
@property templateName
@type String
@default null
@since 1.4.0
@public
*/
templateName: null,
/**
The name of the controller to associate with this route.
By default, Ember will lookup a route's controller that matches the name
of the route (i.e. `App.PostController` for `App.PostRoute`). However,
if you would like to define a specific controller to use, you can do so
using this property.
This is useful in many ways, as the controller specified will be:
* passed to the `setupController` method.
* used as the controller for the view being rendered by the route.
* returned from a call to `controllerFor` for the route.
@property controllerName
@type String
@default null
@since 1.4.0
@public
*/
controllerName: null,
/**
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:
```javascript
App.ContactFormRoute = Ember.Route.extend({
actions: {
willTransition: function(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()`.
@event willTransition
@param {Transition} transition
@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.
```javascript
App.LoginRoute = Ember.Route.extend({
actions: {
didTransition: function() {
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.
```javascript
App.ApplicationRoute = Ember.Route.extend({
actions: {
loading: function(transition, route) {
var view = Ember.View.create({
classNames: ['app-loading']
})
.append();
this.router.one('didTransition', function() {
view.destroy();
});
return true; // Bubble the loading event
}
}
});
```
@event loading
@param {Transition} transition
@param {Ember.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:
```javascript
App.AdminRoute = Ember.Route.extend({
beforeModel: function() {
return Ember.RSVP.reject('bad things!');
},
actions: {
error: function(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`:
```javascript
App.ApplicationRoute = Ember.Route.extend({
actions: {
error: function(error, transition) {
this.controllerFor('banner').displayError(error.message);
}
}
});
```
@event error
@param {Error} error
@param {Transition} transition
@public
*/
/**
This event is triggered when the router enters the route. It is
not executed when the model for the route changes.
```javascript
App.ApplicationRoute = Ember.Route.extend({
collectAnalytics: function(){
collectAnalytics();
}.on('activate')
});
```
@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.
```javascript
App.IndexRoute = Ember.Route.extend({
trackPageLeaveAnalytics: function(){
trackPageLeaveAnalytics();
}.on('deactivate')
});
```
@event deactivate
@since 1.9.0
@public
*/
/**
The controller associated with this route.
Example
```javascript
App.FormRoute = Ember.Route.extend({
actions: {
willTransition: function(transition) {
if (this.controller.get('userHasEnteredData') &&
!confirm('Are you sure you want to abandon progress?')) {
transition.abort();
} else {
// Bubble the `willTransition` action so that
// parent routes can decide whether or not to abort.
return true;
}
}
}
});
```
@property controller
@type Ember.Controller
@since 1.6.0
@private
*/
_actions: {
queryParamsDidChange(changed, totalPresent, removed) {
var qpMap = get(this, '_qp').map;
var totalChanged = keys(changed).concat(keys(removed));
for (var i = 0, len = totalChanged.length; i < len; ++i) {
var qp = qpMap[totalChanged[i]];
if (qp && get(this._optionsForQueryParam(qp), 'refreshModel')) {
this.refresh();
}
}
return true;
},
finalizeQueryParamChange(params, finalParams, transition) {
if (this.routeName !== 'application') { return true; }
// Transition object is absent for intermediate transitions.
if (!transition) { return; }
var handlerInfos = transition.state.handlerInfos;
var router = this.router;
var qpMeta = router._queryParamsFor(handlerInfos[handlerInfos.length-1].name);
var changes = router._qpUpdates;
var replaceUrl;
stashParamNames(router, handlerInfos);
for (var i = 0, len = qpMeta.qps.length; i < len; ++i) {
var qp = qpMeta.qps[i];
var route = qp.route;
var controller = route.controller;
var presentKey = qp.urlKey in params && qp.urlKey;
// Do a reverse lookup to see if the changed query
// param URL key corresponds to a QP property on
// this controller.
var value, svalue;
if (changes && qp.urlKey in changes) {
// Value updated in/before setupController
value = get(controller, qp.prop);
svalue = route.serializeQueryParam(value, qp.urlKey, qp.type);
} else {
if (presentKey) {
svalue = params[presentKey];
value = route.deserializeQueryParam(svalue, qp.urlKey, qp.type);
} else {
// No QP provided; use default value.
svalue = qp.sdef;
value = copyDefaultValue(qp.def);
}
}
controller._qpDelegate = null;
var thisQueryParamChanged = (svalue !== qp.svalue);
if (thisQueryParamChanged) {
if (transition.queryParamsOnly && replaceUrl !== false) {
var options = route._optionsForQueryParam(qp);
var replaceConfigValue = get(options, 'replace');
if (replaceConfigValue) {
replaceUrl = true;
} else if (replaceConfigValue === false) {
// Explicit pushState wins over any other replaceStates.
replaceUrl = false;
}
}
set(controller, qp.prop, value);
}
// Stash current serialized value of controller.
qp.svalue = svalue;
var thisQueryParamHasDefaultValue = (qp.sdef === svalue);
if (!thisQueryParamHasDefaultValue) {
finalParams.push({
value: svalue,
visible: true,
key: presentKey || qp.urlKey
});
}
}
if (replaceUrl) {
transition.method('replace');
}
forEach(qpMeta.qps, function(qp) {
var routeQpMeta = get(qp.route, '_qp');
var finalizedController = qp.route.controller;
finalizedController._qpDelegate = get(routeQpMeta, 'states.active');
});
router._qpUpdates = null;
}
},
/**
@deprecated
Please use `actions` instead.
@method events
@private
*/
events: null,
/**
This hook is executed when the router completely exits this route. It is
not executed when the model for the route changes.
@method deactivate
@public
*/
deactivate: K,
/**
This hook is executed when the router enters the route. It is not executed
when the model for the route changes.
@method activate
@public
*/
activate: K,
/**
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
resource tree.
```javascript
App.Router.map(function() {
this.resource('blogPost', { path:':blogPostId' }, function() {
this.resource('blogComment', { path: ':blogCommentId' });
});
});
this.transitionTo('blogComment', aPost, aComment);
this.transitionTo('blogComment', 1, 13);
```
It is also possible to pass a URL (a string that starts with a
`/`). This is intended for testing and debugging purposes and
should rarely be used in production code.
```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'.
Simple Transition Example
```javascript
App.Router.map(function() {
this.route('index');
this.route('secret');
this.route('fourOhFour', { path: '*:' });
});
App.IndexRoute = Ember.Route.extend({
actions: {
moveToSecret: function(context) {
if (authorized()) {
this.transitionTo('secret', context);
} else {
this.transitionTo('fourOhFour');
}
}
}
});
```
Transition to a nested route
```javascript
App.Router.map(function() {
this.resource('articles', { path: '/articles' }, function() {
this.route('new');
});
});
App.IndexRoute = Ember.Route.extend({
actions: {
transitionToNewArticle: function() {
this.transitionTo('articles.new');
}
}
});
```
Multiple Models Example
```javascript
App.Router.map(function() {
this.route('index');
this.resource('breakfast', { path: ':breakfastId' }, function() {
this.resource('cereal', { path: ':cerealId' });
});
});
App.IndexRoute = Ember.Route.extend({
actions: {
moveToChocolateCereal: function() {
var cereal = { cerealId: 'ChocolateYumminess' };
var breakfast = { breakfastId: 'CerealAndMilk' };
this.transitionTo('cereal', breakfast, cereal);
}
}
});
```
Nested Route with Query String Example
```javascript
App.Router.map(function() {
this.resource('fruits', function() {
this.route('apples');
});
});
App.IndexRoute = Ember.Route.extend({
actions: {
transitionToApples: function() {
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
@public
*/
transitionTo(name, context) {
var router = this.router;
return router.transitionTo(...arguments);
},
/**
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
@private
*/
intermediateTransitionTo() {
var router = this.router;
router.intermediateTransitionTo(...arguments);
},
/**
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