-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrouting.js
1693 lines (1297 loc) · 46 KB
/
routing.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
//
// This file is automatically generated. any changes will be lost
//
require("./views");
require("./states");
(function() {
var get = Ember.get;
Ember._ResolvedState = Ember.Object.extend({
manager: null,
state: null,
match: null,
object: Ember.computed(function(key, value) {
if (arguments.length === 2) {
this._object = value;
return value;
} else {
if (this._object) {
return this._object;
} else {
var state = get(this, 'state'),
match = get(this, 'match'),
manager = get(this, 'manager');
return state.deserialize(manager, match.hash);
}
}
}).property(),
hasPromise: Ember.computed(function() {
return Ember.canInvoke(get(this, 'object'), 'then');
}).property('object'),
promise: Ember.computed(function() {
var object = get(this, 'object');
if (Ember.canInvoke(object, 'then')) {
return object;
} else {
return {
then: function(success) { success(object); }
};
}
}).property('object'),
transition: function() {
var manager = get(this, 'manager'),
path = get(this, 'state.path'),
object = get(this, 'object');
manager.transitionTo(path, object);
}
});
})();
(function() {
/**
@module ember
@submodule ember-routing
*/
var get = Ember.get;
// The Ember Routable mixin assumes the existance of a simple
// routing shim that supports the following three behaviors:
//
// * .getURL() - this is called when the page loads
// * .setURL(newURL) - this is called from within the state
// manager when the state changes to a routable state
// * .onURLChange(callback) - this happens when the user presses
// the back or forward button
var paramForClass = function(classObject) {
var className = classObject.toString(),
parts = className.split("."),
last = parts[parts.length - 1];
return Ember.String.underscore(last) + "_id";
};
var merge = function(original, hash) {
for (var prop in hash) {
if (!hash.hasOwnProperty(prop)) { continue; }
if (original.hasOwnProperty(prop)) { continue; }
original[prop] = hash[prop];
}
};
/**
@class Routable
@namespace Ember
@extends Ember.Mixin
*/
Ember.Routable = Ember.Mixin.create({
init: function() {
var redirection;
this.on('setup', this, this.stashContext);
if (redirection = get(this, 'redirectsTo')) {
Ember.assert("You cannot use `redirectsTo` if you already have a `connectOutlets` method", this.connectOutlets === Ember.K);
this.connectOutlets = function(router) {
router.transitionTo(redirection);
};
}
// normalize empty route to '/'
var route = get(this, 'route');
if (route === '') {
route = '/';
}
this._super();
Ember.assert("You cannot use `redirectsTo` on a state that has child states", !redirection || (!!redirection && !!get(this, 'isLeaf')));
},
setup: function() {
return this.connectOutlets.apply(this, arguments);
},
/**
@private
Whenever a routable state is entered, the context it was entered with
is stashed so that we can regenerate the state's `absoluteURL` on
demand.
@method stashContext
@param manager {Ember.StateManager}
@param context
*/
stashContext: function(manager, context) {
this.router = manager;
var serialized = this.serialize(manager, context);
Ember.assert('serialize must return a hash', !serialized || typeof serialized === 'object');
manager.setStateMeta(this, 'context', context);
manager.setStateMeta(this, 'serialized', serialized);
if (get(this, 'isRoutable') && !get(manager, 'isRouting')) {
this.updateRoute(manager, get(manager, 'location'));
}
},
/**
@private
Whenever a routable state is entered, the router's location object
is notified to set the URL to the current absolute path.
In general, this will update the browser's URL.
@method updateRoute
@param manager {Ember.StateManager}
@param location {Ember.Location}
*/
updateRoute: function(manager, location) {
if (get(this, 'isLeafRoute')) {
var path = this.absoluteRoute(manager);
location.setURL(path);
}
},
/**
@private
Get the absolute route for the current state and a given
hash.
This method is private, as it expects a serialized hash,
not the original context object.
@method absoluteRoute
@param manager {Ember.StateManager}
@param hash {Hash}
*/
absoluteRoute: function(manager, hash) {
var parentState = get(this, 'parentState');
var path = '', generated;
// If the parent state is routable, use its current path
// as this route's prefix.
if (get(parentState, 'isRoutable')) {
path = parentState.absoluteRoute(manager, hash);
}
var matcher = get(this, 'routeMatcher'),
serialized = manager.getStateMeta(this, 'serialized');
// merge the existing serialized object in with the passed
// in hash.
hash = hash || {};
merge(hash, serialized);
generated = matcher && matcher.generate(hash);
if (generated) {
path = path + '/' + generated;
}
return path;
},
/**
@private
At the moment, a state is routable if it has a string `route`
property. This heuristic may change.
@property isRoutable
@type Boolean
*/
isRoutable: Ember.computed(function() {
return typeof get(this, 'route') === 'string';
}),
/**
@private
Determine if this is the last routeable state
@property isLeafRoute
@type Boolean
*/
isLeafRoute: Ember.computed(function() {
if (get(this, 'isLeaf')) { return true; }
return !get(this, 'childStates').findProperty('isRoutable');
}),
/**
@private
A _RouteMatcher object generated from the current route's `route`
string property.
@property routeMatcher
@type Ember._RouteMatcher
*/
routeMatcher: Ember.computed(function() {
var route = get(this, 'route');
if (route) {
return Ember._RouteMatcher.create({ route: route });
}
}),
/**
@private
Check whether the route has dynamic segments and therefore takes
a context.
@property hasContext
@type Boolean
*/
hasContext: Ember.computed(function() {
var routeMatcher = get(this, 'routeMatcher');
if (routeMatcher) {
return routeMatcher.identifiers.length > 0;
}
}),
/**
@private
The model class associated with the current state. This property
uses the `modelType` property, in order to allow it to be
specified as a String.
@property modelClass
@type Ember.Object
*/
modelClass: Ember.computed(function() {
var modelType = get(this, 'modelType');
if (typeof modelType === 'string') {
return Ember.get(Ember.lookup, modelType);
} else {
return modelType;
}
}),
/**
@private
Get the model class for the state. The heuristic is:
* The state must have a single dynamic segment
* The dynamic segment must end in `_id`
* A dynamic segment like `blog_post_id` is converted into `BlogPost`
* The name is then looked up on the passed in namespace
The process of initializing an application with a router will
pass the application's namespace into the router, which will be
used here.
@method modelClassFor
@param namespace {Ember.Namespace}
*/
modelClassFor: function(namespace) {
var modelClass, routeMatcher, identifiers, match, className;
// if an explicit modelType was specified, use that
if (modelClass = get(this, 'modelClass')) { return modelClass; }
// if the router has no lookup namespace, we won't be able to guess
// the modelType
if (!namespace) { return; }
// make sure this state is actually a routable state
routeMatcher = get(this, 'routeMatcher');
if (!routeMatcher) { return; }
// only guess modelType for states with a single dynamic segment
// (no more, no fewer)
identifiers = routeMatcher.identifiers;
if (identifiers.length !== 2) { return; }
// extract the `_id` from the end of the dynamic segment; if the
// dynamic segment does not end in `_id`, we can't guess the
// modelType
match = identifiers[1].match(/^(.*)_id$/);
if (!match) { return; }
// convert the underscored type into a class form and look it up
// on the router's namespace
className = Ember.String.classify(match[1]);
return get(namespace, className);
},
/**
The default method that takes a `params` object and converts
it into an object.
By default, a params hash that looks like `{ post_id: 1 }`
will be looked up as `namespace.Post.find(1)`. This is
designed to work seamlessly with Ember Data, but will work
fine with any class that has a `find` method.
@method deserialize
@param manager {Ember.StateManager}
@param params {Hash}
*/
deserialize: function(manager, params) {
var modelClass, routeMatcher, param;
if (modelClass = this.modelClassFor(get(manager, 'namespace'))) {
Ember.assert("Expected "+modelClass.toString()+" to implement `find` for use in '"+this.get('path')+"' `deserialize`. Please implement the `find` method or overwrite `deserialize`.", modelClass.find);
return modelClass.find(params[paramForClass(modelClass)]);
}
return params;
},
/**
The default method that takes an object and converts it into
a params hash.
By default, if there is a single dynamic segment named
`blog_post_id` and the object is a `BlogPost` with an
`id` of `12`, the serialize method will produce:
{ blog_post_id: 12 }
@method serialize
@param manager {Ember.StateManager}
@param context
*/
serialize: function(manager, context) {
var modelClass, routeMatcher, namespace, param, id;
if (Ember.empty(context)) { return ''; }
if (modelClass = this.modelClassFor(get(manager, 'namespace'))) {
param = paramForClass(modelClass);
id = get(context, 'id');
context = {};
context[param] = id;
}
return context;
},
/**
@private
@method resolvePath
@param manager {Ember.StateManager}
@param path {String}
*/
resolvePath: function(manager, path) {
if (get(this, 'isLeafRoute')) { return Ember.A(); }
var childStates = get(this, 'childStates'), match;
childStates = Ember.A(childStates.filterProperty('isRoutable'));
childStates = childStates.sort(function(a, b) {
var aDynamicSegments = get(a, 'routeMatcher.identifiers.length'),
bDynamicSegments = get(b, 'routeMatcher.identifiers.length'),
aRoute = get(a, 'route'),
bRoute = get(b, 'route');
if (aRoute.indexOf(bRoute) === 0) {
return -1;
} else if (bRoute.indexOf(aRoute) === 0) {
return 1;
}
if (aDynamicSegments !== bDynamicSegments) {
return aDynamicSegments - bDynamicSegments;
}
return get(b, 'route.length') - get(a, 'route.length');
});
var state = childStates.find(function(state) {
var matcher = get(state, 'routeMatcher');
if (match = matcher.match(path)) { return true; }
});
Ember.assert("Could not find state for path " + path, !!state);
var resolvedState = Ember._ResolvedState.create({
manager: manager,
state: state,
match: match
});
var states = state.resolvePath(manager, match.remaining);
return Ember.A([resolvedState]).pushObjects(states);
},
/**
@private
Once `unroute` has finished unwinding, `routePath` will be called
with the remainder of the route.
For example, if you were in the /posts/1/comments state, and you
moved into the /posts/2/comments state, `routePath` will be called
on the state whose path is `/posts` with the path `/2/comments`.
@method routePath
@param manager {Ember.StateManager}
@param path {String}
*/
routePath: function(manager, path) {
if (get(this, 'isLeafRoute')) { return; }
var resolvedStates = this.resolvePath(manager, path),
hasPromises = resolvedStates.some(function(s) { return get(s, 'hasPromise'); });
function runTransition() {
resolvedStates.forEach(function(rs) { rs.transition(); });
}
if (hasPromises) {
manager.transitionTo('loading');
Ember.assert('Loading state should be the child of a route', Ember.Routable.detect(get(manager, 'currentState.parentState')));
Ember.assert('Loading state should not be a route', !Ember.Routable.detect(get(manager, 'currentState')));
manager.handleStatePromises(resolvedStates, runTransition);
} else {
runTransition();
}
},
/**
@private
When you move to a new route by pressing the back
or forward button, this method is called first.
Its job is to move the state manager into a parent
state of the state it will eventually move into.
@method unroutePath
@param router {Ember.Router}
@param path {String}
*/
unroutePath: function(router, path) {
var parentState = get(this, 'parentState');
// If we're at the root state, we're done
if (parentState === router) {
return;
}
path = path.replace(/^(?=[^\/])/, "/");
var absolutePath = this.absoluteRoute(router);
var route = get(this, 'route');
// If the current path is empty, move up one state,
// because the index ('/') state must be a leaf node.
if (route !== '/') {
// If the current path is a prefix of the path we're trying
// to go to, we're done.
var index = path.indexOf(absolutePath),
next = path.charAt(absolutePath.length);
if (index === 0 && (next === "/" || next === "")) {
return;
}
}
// Transition to the parent and call unroute again.
router.enterState({
exitStates: [this],
enterStates: [],
finalState: parentState
});
router.send('unroutePath', path);
},
parentTemplate: Ember.computed(function() {
var state = this, parentState, template;
while (state = get(state, 'parentState')) {
if (template = get(state, 'template')) {
return template;
}
}
return 'application';
}),
_template: Ember.computed(function(key, value) {
if (arguments.length > 1) { return value; }
if (value = get(this, 'template')) {
return value;
}
// If no template was explicitly supplied convert
// the class name into a template name. For example,
// App.PostRoute will return `post`.
var className = this.constructor.toString(), baseName;
if (/^[^\[].*Route$/.test(className)) {
baseName = className.match(/([^\.]+\.)*([^\.]+)/)[2];
baseName = baseName.replace(/Route$/, '');
return baseName.charAt(0).toLowerCase() + baseName.substr(1);
}
}),
render: function(options) {
options = options || {};
var template = options.template || get(this, '_template'),
parentTemplate = options.into || get(this, 'parentTemplate'),
controller = get(this.router, parentTemplate + "Controller");
var viewName = Ember.String.classify(template) + "View",
viewClass = get(get(this.router, 'namespace'), viewName);
viewClass = (viewClass || Ember.View).extend({
templateName: template
});
controller.set('view', viewClass.create());
},
/**
The `connectOutlets` event will be triggered once a
state has been entered. It will be called with the
route's context.
@event connectOutlets
@param router {Ember.Router}
@param [context*]
*/
connectOutlets: Ember.K,
/**
The `navigateAway` event will be triggered when the
URL changes due to the back/forward button
@event navigateAway
*/
navigateAway: Ember.K
});
})();
(function() {
/**
@module ember
@submodule ember-routing
*/
/**
@class Route
@namespace Ember
@extends Ember.State
@uses Ember.Routable
*/
Ember.Route = Ember.State.extend(Ember.Routable);
})();
(function() {
var escapeForRegex = function(text) {
return text.replace(/[\-\[\]{}()*+?.,\\\^\$|#\s]/g, "\\$&");
};
/**
@class _RouteMatcher
@namespace Ember
@private
@extends Ember.Object
*/
Ember._RouteMatcher = Ember.Object.extend({
state: null,
init: function() {
var route = this.route,
identifiers = [],
count = 1,
escaped;
// Strip off leading slash if present
if (route.charAt(0) === '/') {
route = this.route = route.substr(1);
}
escaped = escapeForRegex(route);
var regex = escaped.replace(/:([a-z_]+)(?=$|\/)/gi, function(match, id) {
identifiers[count++] = id;
return "([^/]+)";
});
this.identifiers = identifiers;
this.regex = new RegExp("^/?" + regex);
},
match: function(path) {
var match = path.match(this.regex);
if (match) {
var identifiers = this.identifiers,
hash = {};
for (var i=1, l=identifiers.length; i<l; i++) {
hash[identifiers[i]] = match[i];
}
return {
remaining: path.substr(match[0].length),
hash: identifiers.length > 0 ? hash : null
};
}
},
generate: function(hash) {
var identifiers = this.identifiers, route = this.route, id;
for (var i=1, l=identifiers.length; i<l; i++) {
id = identifiers[i];
route = route.replace(new RegExp(":" + id), hash[id]);
}
return route;
}
});
})();
(function() {
/**
@module ember
@submodule ember-routing
*/
var get = Ember.get, set = Ember.set;
/*
This file implements the `location` API used by Ember's router.
That API is:
getURL: returns the current URL
setURL(path): sets the current URL
onUpdateURL(callback): triggers the callback when the URL changes
formatURL(url): formats `url` to be placed into `href` attribute
Calling setURL will not trigger onUpdateURL callbacks.
TODO: This should perhaps be moved so that it's visible in the doc output.
*/
/**
Ember.Location returns an instance of the correct implementation of
the `location` API.
You can pass it a `implementation` ('hash', 'history', 'none') to force a
particular implementation.
@class Location
@namespace Ember
@static
*/
Ember.Location = {
create: function(options) {
var implementation = options && options.implementation;
Ember.assert("Ember.Location.create: you must specify a 'implementation' option", !!implementation);
var implementationClass = this.implementations[implementation];
Ember.assert("Ember.Location.create: " + implementation + " is not a valid implementation", !!implementationClass);
return implementationClass.create.apply(implementationClass, arguments);
},
registerImplementation: function(name, implementation) {
this.implementations[name] = implementation;
},
implementations: {}
};
})();
(function() {
/**
@module ember
@submodule ember-routing
*/
var get = Ember.get, set = Ember.set;
/**
Ember.NoneLocation does not interact with the browser. It is useful for
testing, or when you need to manage state with your Router, but temporarily
don't want it to muck with the URL (for example when you embed your
application in a larger page).
@class NoneLocation
@namespace Ember
@extends Ember.Object
*/
Ember.NoneLocation = Ember.Object.extend({
path: '',
getURL: function() {
return get(this, 'path');
},
setURL: function(path) {
set(this, 'path', path);
},
onUpdateURL: function(callback) {
// We are not wired up to the browser, so we'll never trigger the callback.
},
formatURL: function(url) {
// The return value is not overly meaningful, but we do not want to throw
// errors when test code renders templates containing {{action href=true}}
// helpers.
return url;
}
});
Ember.Location.registerImplementation('none', Ember.NoneLocation);
})();
(function() {
/**
@module ember
@submodule ember-routing
*/
var get = Ember.get, set = Ember.set;
/**
Ember.HashLocation implements the location API using the browser's
hash. At present, it relies on a hashchange event existing in the
browser.
@class HashLocation
@namespace Ember
@extends Ember.Object
*/
Ember.HashLocation = Ember.Object.extend({
init: function() {
set(this, 'location', get(this, 'location') || window.location);
},
/**
@private
Returns the current `location.hash`, minus the '#' at the front.
@method getURL
*/
getURL: function() {
return get(this, 'location').hash.substr(1);
},
/**
@private
Set the `location.hash` and remembers what was set. This prevents
`onUpdateURL` callbacks from triggering when the hash was set by
`HashLocation`.
@method setURL
@param path {String}
*/
setURL: function(path) {
get(this, 'location').hash = path;
set(this, 'lastSetURL', path);
},
/**
@private
Register a callback to be invoked when the hash changes. These
callbacks will execute when the user presses the back or forward
button, but not after `setURL` is invoked.
@method onUpdateURL
@param callback {Function}
*/
onUpdateURL: function(callback) {
var self = this;
var guid = Ember.guidFor(this);
Ember.$(window).bind('hashchange.ember-location-'+guid, function() {
var path = location.hash.substr(1);
if (get(self, 'lastSetURL') === path) { return; }
set(self, 'lastSetURL', null);
callback(location.hash.substr(1));
});
},
/**
@private
Given a URL, formats it to be placed into the page as part
of an element's `href` attribute.
This is used, for example, when using the {{action}} helper
to generate a URL based on an event.
@method formatURL
@param url {String}
*/
formatURL: function(url) {
return '#'+url;
},
willDestroy: function() {
var guid = Ember.guidFor(this);
Ember.$(window).unbind('hashchange.ember-location-'+guid);
}
});
Ember.Location.registerImplementation('hash', Ember.HashLocation);
})();
(function() {
/**
@module ember
@submodule ember-routing
*/
var get = Ember.get, set = Ember.set;
var popstateReady = false;
/**
Ember.HistoryLocation implements the location API using the browser's
history.pushState API.
@class HistoryLocation
@namespace Ember
@extends Ember.Object
*/
Ember.HistoryLocation = Ember.Object.extend({
init: function() {
set(this, 'location', get(this, 'location') || window.location);
this.initState();
},
/**
@private
Used to set state on first call to setURL
@method initState
*/
initState: function() {
this.replaceState(get(this, 'location').pathname);
set(this, 'history', window.history);
},
/**
Will be pre-pended to path upon state change
@property rootURL
@default '/'
*/
rootURL: '/',
/**
@private
Returns the current `location.pathname`.
@method getURL
*/
getURL: function() {
return get(this, 'location').pathname;
},
/**
@private
Uses `history.pushState` to update the url without a page reload.
@method setURL
@param path {String}
*/
setURL: function(path) {
path = this.formatURL(path);
if (this.getState().path !== path) {
popstateReady = true;
this.pushState(path);
}
},
/**
@private
Get the current `history.state`
@method getState
*/
getState: function() {
return get(this, 'history').state;
},
/**
@private
Pushes a new state
@method pushState
@param path {String}
*/
pushState: function(path) {
window.history.pushState({ path: path }, null, path);
},
/**
@private
Replaces the current state
@method replaceState
@param path {String}
*/
replaceState: function(path) {
window.history.replaceState({ path: path }, null, path);
},
/**
@private
Register a callback to be invoked whenever the browser
history changes, including using forward and back buttons.
@method onUpdateURL