From ca8cc0af2e04e9f299ba49f5fac01d28b7d2ab1d Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Mon, 19 Sep 2016 08:05:59 -0500 Subject: [PATCH] feat(nav): set default stack history on app init --- src/components/nav/test/basic/app-module.ts | 4 ++-- src/navigation/nav-util.ts | 9 ++++++--- src/navigation/test/nav-util.spec.ts | 12 ++++++++++++ src/navigation/url-serializer.ts | 6 ++++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/components/nav/test/basic/app-module.ts b/src/components/nav/test/basic/app-module.ts index 61fee90a52..08f1367751 100644 --- a/src/components/nav/test/basic/app-module.ts +++ b/src/components/nav/test/basic/app-module.ts @@ -490,8 +490,8 @@ export const deepLinkConfig: DeepLinkConfig = { { component: FirstPage, name: 'first-page' }, { component: AnotherPage, name: 'another-page' }, { component: MyCmpTest, name: 'tab1-page1' }, - { component: FullPage, name: 'full-page' }, - { component: PrimaryHeaderPage, name: 'primary-header-page' }, + { component: FullPage, name: 'full-page', defaultHistory: ['first-page', 'another-page'] }, + { component: PrimaryHeaderPage, name: 'primary-header-page', defaultHistory: ['first-page', 'full-page'] }, ] }; diff --git a/src/navigation/nav-util.ts b/src/navigation/nav-util.ts index df9b2d8013..4393818290 100644 --- a/src/navigation/nav-util.ts +++ b/src/navigation/nav-util.ts @@ -1,7 +1,7 @@ import { Renderer, TypeDecorator } from '@angular/core'; import { DeepLinker } from './deep-linker'; -import { isPresent } from '../util/util'; +import { isArray, isPresent } from '../util/util'; import { isViewController, ViewController } from './view-controller'; import { NavControllerBase } from './nav-controller-base'; import { Transition } from '../transitions/transition'; @@ -32,15 +32,18 @@ export function convertToView(linker: DeepLinker, nameOrPageOrView: any, params: export function convertToViews(linker: DeepLinker, pages: any[]): ViewController[] { const views: ViewController[] = []; - if (pages) { + if (isArray(pages)) { for (var i = 0; i < pages.length; i++) { var page = pages[i]; if (page) { if (isViewController(page)) { views.push(page); - } else { + } else if (page.page) { views.push(convertToView(linker, page.page, page.params)); + + } else { + views.push(convertToView(linker, page, null)); } } } diff --git a/src/navigation/test/nav-util.spec.ts b/src/navigation/test/nav-util.spec.ts index 171bf1daf6..23b757689f 100644 --- a/src/navigation/test/nav-util.spec.ts +++ b/src/navigation/test/nav-util.spec.ts @@ -18,6 +18,18 @@ describe('NavUtil', () => { }); it('should convert all string names', () => { + let linker = mockDeepLinker({ + links: [{ component: MockView, name: 'someName' }] + }); + let pages = ['someName', 'someName', 'someName']; + let views = convertToViews(linker, pages); + expect(views.length).toEqual(3); + expect(views[0].component).toEqual(MockView); + expect(views[1].component).toEqual(MockView); + expect(views[2].component).toEqual(MockView); + }); + + it('should convert all page string names', () => { let linker = mockDeepLinker({ links: [{ component: MockView, name: 'someName' }] }); diff --git a/src/navigation/url-serializer.ts b/src/navigation/url-serializer.ts index 257b3ef489..085c4a54d5 100644 --- a/src/navigation/url-serializer.ts +++ b/src/navigation/url-serializer.ts @@ -42,7 +42,8 @@ export class UrlSerializer { id: configLink.name, name: configLink.name, component: configLink.component, - data: null + data: null, + defaultHistory: configLink.defaultHistory } : null; } @@ -174,7 +175,8 @@ export const fillMatchedUrlParts = (segments: NavSegment[], urlParts: string[], id: matchedUrlParts.join('/'), name: configLink.name, component: configLink.component, - data: createMatchedData(matchedUrlParts, configLink) + data: createMatchedData(matchedUrlParts, configLink), + defaultHistory: configLink.defaultHistory }; } }