Skip to content

Commit ca8cc0a

Browse files
committed
feat(nav): set default stack history on app init
1 parent 50e445e commit ca8cc0a

4 files changed

Lines changed: 24 additions & 7 deletions

File tree

‎src/components/nav/test/basic/app-module.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ export const deepLinkConfig: DeepLinkConfig = {
490490
{ component: FirstPage, name: 'first-page' },
491491
{ component: AnotherPage, name: 'another-page' },
492492
{ component: MyCmpTest, name: 'tab1-page1' },
493-
{ component: FullPage, name: 'full-page' },
494-
{ component: PrimaryHeaderPage, name: 'primary-header-page' },
493+
{ component: FullPage, name: 'full-page', defaultHistory: ['first-page', 'another-page'] },
494+
{ component: PrimaryHeaderPage, name: 'primary-header-page', defaultHistory: ['first-page', 'full-page'] },
495495
]
496496
};
497497

‎src/navigation/nav-util.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Renderer, TypeDecorator } from '@angular/core';
22

33
import { DeepLinker } from './deep-linker';
4-
import { isPresent } from '../util/util';
4+
import { isArray, isPresent } from '../util/util';
55
import { isViewController, ViewController } from './view-controller';
66
import { NavControllerBase } from './nav-controller-base';
77
import { Transition } from '../transitions/transition';
@@ -32,15 +32,18 @@ export function convertToView(linker: DeepLinker, nameOrPageOrView: any, params:
3232

3333
export function convertToViews(linker: DeepLinker, pages: any[]): ViewController[] {
3434
const views: ViewController[] = [];
35-
if (pages) {
35+
if (isArray(pages)) {
3636
for (var i = 0; i < pages.length; i++) {
3737
var page = pages[i];
3838
if (page) {
3939
if (isViewController(page)) {
4040
views.push(page);
4141

42-
} else {
42+
} else if (page.page) {
4343
views.push(convertToView(linker, page.page, page.params));
44+
45+
} else {
46+
views.push(convertToView(linker, page, null));
4447
}
4548
}
4649
}

‎src/navigation/test/nav-util.spec.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ describe('NavUtil', () => {
1818
});
1919

2020
it('should convert all string names', () => {
21+
let linker = mockDeepLinker({
22+
links: [{ component: MockView, name: 'someName' }]
23+
});
24+
let pages = ['someName', 'someName', 'someName'];
25+
let views = convertToViews(linker, pages);
26+
expect(views.length).toEqual(3);
27+
expect(views[0].component).toEqual(MockView);
28+
expect(views[1].component).toEqual(MockView);
29+
expect(views[2].component).toEqual(MockView);
30+
});
31+
32+
it('should convert all page string names', () => {
2133
let linker = mockDeepLinker({
2234
links: [{ component: MockView, name: 'someName' }]
2335
});

‎src/navigation/url-serializer.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export class UrlSerializer {
4242
id: configLink.name,
4343
name: configLink.name,
4444
component: configLink.component,
45-
data: null
45+
data: null,
46+
defaultHistory: configLink.defaultHistory
4647
} : null;
4748
}
4849

@@ -174,7 +175,8 @@ export const fillMatchedUrlParts = (segments: NavSegment[], urlParts: string[],
174175
id: matchedUrlParts.join('/'),
175176
name: configLink.name,
176177
component: configLink.component,
177-
data: createMatchedData(matchedUrlParts, configLink)
178+
data: createMatchedData(matchedUrlParts, configLink),
179+
defaultHistory: configLink.defaultHistory
178180
};
179181
}
180182
}

0 commit comments

Comments
 (0)