mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor(nav): restructure nav component to separate modules, support async component loading
restructure nav component to separate modules, support async component loading
This commit is contained in:
39
src/components/nav/nav-pop-anchor.ts
Normal file
39
src/components/nav/nav-pop-anchor.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { AfterContentInit, Directive, Optional } from '@angular/core';
|
||||
|
||||
import { DeepLinker } from '../../navigation/deep-linker';
|
||||
import { ViewController } from '../../navigation/view-controller';
|
||||
|
||||
import { NavPop } from './nav-pop';
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@Directive({
|
||||
selector: 'a[navPop]',
|
||||
host: {
|
||||
'[attr.href]': '_href'
|
||||
}
|
||||
})
|
||||
export class NavPopAnchor implements AfterContentInit {
|
||||
|
||||
_href: string;
|
||||
|
||||
constructor(
|
||||
@Optional() public host: NavPop,
|
||||
public linker: DeepLinker,
|
||||
@Optional() public viewCtrl: ViewController) {}
|
||||
|
||||
updateHref() {
|
||||
if (this.host && this.viewCtrl) {
|
||||
const previousView = this.host._nav.getPrevious(this.viewCtrl);
|
||||
this._href = (previousView && this.linker.createUrl(this.host._nav, this.viewCtrl.component, this.viewCtrl.data)) || '#';
|
||||
|
||||
} else {
|
||||
this._href = '#';
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterContentInit() {
|
||||
this.updateHref();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
import { AfterContentInit, Directive, HostListener, Optional } from '@angular/core';
|
||||
import { Directive, HostListener, Optional } from '@angular/core';
|
||||
|
||||
import { DeepLinker } from '../../navigation/deep-linker';
|
||||
import { NavController } from '../../navigation/nav-controller';
|
||||
import { ViewController } from '../../navigation/view-controller';
|
||||
|
||||
|
||||
/**
|
||||
@@ -53,38 +51,3 @@ export class NavPop {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@Directive({
|
||||
selector: 'a[navPop]',
|
||||
host: {
|
||||
'[attr.href]': '_href'
|
||||
}
|
||||
})
|
||||
export class NavPopAnchor implements AfterContentInit {
|
||||
|
||||
_href: string;
|
||||
|
||||
constructor(
|
||||
@Optional() public host: NavPop,
|
||||
public linker: DeepLinker,
|
||||
@Optional() public viewCtrl: ViewController) {}
|
||||
|
||||
updateHref() {
|
||||
if (this.host && this.viewCtrl) {
|
||||
const previousView = this.host._nav.getPrevious(this.viewCtrl);
|
||||
this._href = (previousView && this.linker.createUrl(this.host._nav, this.viewCtrl.component, this.viewCtrl.data)) || '#';
|
||||
|
||||
} else {
|
||||
this._href = '#';
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterContentInit() {
|
||||
this.updateHref();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
36
src/components/nav/nav-push-anchor.ts
Normal file
36
src/components/nav/nav-push-anchor.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { AfterContentInit, Directive, Host, Optional } from '@angular/core';
|
||||
|
||||
import { DeepLinker } from '../../navigation/deep-linker';
|
||||
|
||||
import { NavPush } from './nav-push';
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@Directive({
|
||||
selector: 'a[navPush]',
|
||||
host: {
|
||||
'[attr.href]': '_href'
|
||||
}
|
||||
})
|
||||
export class NavPushAnchor implements AfterContentInit {
|
||||
|
||||
_href: string;
|
||||
|
||||
constructor(
|
||||
@Host() public host: NavPush,
|
||||
@Optional() public linker: DeepLinker) {}
|
||||
|
||||
updateHref() {
|
||||
if (this.host && this.linker) {
|
||||
this._href = this.linker.createUrl(this.host._nav, this.host.navPush, this.host.navParams) || '#';
|
||||
|
||||
} else {
|
||||
this._href = '#';
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterContentInit() {
|
||||
this.updateHref();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import { AfterContentInit, Directive, Host, HostListener, Input, Optional } from '@angular/core';
|
||||
import { Directive, HostListener, Input, Optional } from '@angular/core';
|
||||
|
||||
import { DeepLinker } from '../../navigation/deep-linker';
|
||||
import { NavController } from '../../navigation/nav-controller';
|
||||
|
||||
/**
|
||||
@@ -79,37 +78,4 @@ export class NavPush {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@Directive({
|
||||
selector: 'a[navPush]',
|
||||
host: {
|
||||
'[attr.href]': '_href'
|
||||
}
|
||||
})
|
||||
export class NavPushAnchor implements AfterContentInit {
|
||||
|
||||
_href: string;
|
||||
|
||||
constructor(
|
||||
@Host() public host: NavPush,
|
||||
@Optional() public linker: DeepLinker) {}
|
||||
|
||||
updateHref() {
|
||||
if (this.host && this.linker) {
|
||||
this._href = this.linker.createUrl(this.host._nav, this.host.navPush, this.host.navParams) || '#';
|
||||
|
||||
} else {
|
||||
this._href = '#';
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterContentInit() {
|
||||
this.updateHref();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -111,7 +111,9 @@ export class Nav extends NavControllerBase implements AfterViewInit {
|
||||
let navSegment = this._linker.initNav(this);
|
||||
if (navSegment && navSegment.component) {
|
||||
// there is a segment match in the linker
|
||||
this.setPages(this._linker.initViews(navSegment), null, null);
|
||||
this._linker.initViews(navSegment).then(views => {
|
||||
this.setPages(views, null, null);
|
||||
});
|
||||
|
||||
} else if (this._root) {
|
||||
// no segment match, so use the root property
|
||||
|
||||
Reference in New Issue
Block a user