Skip to content

Commit

Permalink
fix(router): default scroll position restoration to disabled
Browse files Browse the repository at this point in the history
Fixes angular#25145
FW-305 #resolve
  • Loading branch information
jasonaden committed Aug 21, 2018
1 parent b05d4a5 commit ce2d2ae
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/router/src/router_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class RouterModule {
useFactory: provideForRootGuard,
deps: [[Router, new Optional(), new SkipSelf()]]
},
{provide: ROUTER_CONFIGURATION, useValue: config ? config : {}},
{provide: ROUTER_CONFIGURATION, useValue: config},
{
provide: LocationStrategy,
useFactory: provideLocationStrategy,
Expand Down
6 changes: 5 additions & 1 deletion packages/router/src/router_scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export class RouterScroller implements OnDestroy {
/** @docsNotRequired */ public readonly viewportScroller: ViewportScroller, private options: {
scrollPositionRestoration?: 'disabled' | 'enabled' | 'top',
anchorScrolling?: 'disabled'|'enabled'
} = {}) {}
} = {}) {
// Default both options to 'disabled'
options.scrollPositionRestoration = options.scrollPositionRestoration || 'disabled';
options.anchorScrolling = options.anchorScrolling || 'disabled';
}

init(): void {
// we want to disable the automatic scrolling because having two places
Expand Down
18 changes: 18 additions & 0 deletions packages/router/test/router_scroller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ import {Scroll} from '../src/events';
import {RouterScroller} from '../src/router_scroller';

describe('RouterScroller', () => {
it('defaults to disabled', () => {
const events = new Subject<RouterEvent>();
const router = <any>{
events,
parseUrl: (url: any) => new DefaultUrlSerializer().parse(url),
triggerEvent: (e: any) => events.next(e)
};

const viewportScroller = jasmine.createSpyObj(
'viewportScroller',
['getScrollPosition', 'scrollToPosition', 'scrollToAnchor', 'setHistoryScrollRestoration']);
setScroll(viewportScroller, 0, 0);
const scroller = new RouterScroller(router, router);

expect((scroller as any).options.scrollPositionRestoration).toBe('disabled');
expect((scroller as any).options.anchorScrolling).toBe('disabled');
});

describe('scroll to top', () => {
it('should scroll to the top', () => {
const {events, viewportScroller} =
Expand Down
2 changes: 1 addition & 1 deletion packages/router/testing/src/router_testing_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class RouterTestingModule {
ngModule: RouterTestingModule,
providers: [
provideRoutes(routes),
{provide: ROUTER_CONFIGURATION, useValue: config ? config : {}},
{provide: ROUTER_CONFIGURATION, useValue: config},
]
};
}
Expand Down

0 comments on commit ce2d2ae

Please sign in to comment.