File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -31,4 +31,12 @@ export class MockLocationStrategy extends LocationStrategy {
3131 onPopState ( fn : ( value : any ) => void ) : void { ObservableWrapper . subscribe ( this . _subject , fn ) ; }
3232
3333 getBaseHref ( ) : string { return this . internalBaseHref ; }
34+
35+ back ( ) : void {
36+ if ( this . urlChanges . length > 0 ) {
37+ this . urlChanges . pop ( ) ;
38+ var nextUrl = this . urlChanges . length > 0 ? this . urlChanges [ this . urlChanges . length - 1 ] : '' ;
39+ this . simulatePopState ( nextUrl ) ;
40+ }
41+ }
3442}
Original file line number Diff line number Diff line change @@ -83,5 +83,27 @@ export function main() {
8383 . toThrowError (
8484 `No base href set. Either provide a binding to "appBaseHrefToken" or add a base element.` ) ;
8585 } ) ;
86+
87+ it ( 'should revert to the previous path when a back() operation is executed' , ( ) => {
88+ var locationStrategy = new MockLocationStrategy ( ) ;
89+ var location = new Location ( locationStrategy ) ;
90+
91+ location . go ( '/ready' ) ;
92+ assertUrl ( '/ready' ) ;
93+
94+ location . go ( '/ready/set' ) ;
95+ assertUrl ( '/ready/set' ) ;
96+
97+ location . go ( '/ready/set/go' ) ;
98+ assertUrl ( '/ready/set/go' ) ;
99+
100+ location . back ( ) ;
101+ assertUrl ( '/ready/set' ) ;
102+
103+ location . back ( ) ;
104+ assertUrl ( '/ready' ) ;
105+
106+ function assertUrl ( path ) { expect ( location . path ( ) ) . toEqual ( path ) ; }
107+ } ) ;
86108 } ) ;
87109}
You can’t perform that action at this time.
0 commit comments