Skip to content

Commit

Permalink
feat(nav): set default stack history on app init
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Sep 19, 2016
1 parent 50e445e commit ca8cc0a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/components/nav/test/basic/app-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'] },
]
};

Expand Down
9 changes: 6 additions & 3 deletions src/navigation/nav-util.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/navigation/test/nav-util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }]
});
Expand Down
6 changes: 4 additions & 2 deletions src/navigation/url-serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export class UrlSerializer {
id: configLink.name,
name: configLink.name,
component: configLink.component,
data: null
data: null,
defaultHistory: configLink.defaultHistory
} : null;
}

Expand Down Expand Up @@ -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
};
}
}
Expand Down

0 comments on commit ca8cc0a

Please sign in to comment.