Skip to content

Commit

Permalink
fix(router): update path recognizer
Browse files Browse the repository at this point in the history
Closes #5997
  • Loading branch information
adamdbradley committed Apr 6, 2016
1 parent 3733ebc commit 3df5989
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions ionic/components/nav/nav-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,53 +19,28 @@ export class NavRouter extends RouterOutlet {
private _lastUrl: string;

constructor(
_elementRef: ElementRef,
_loader: DynamicComponentLoader,
_parentRouter: Router,
elementRef: ElementRef,
loader: DynamicComponentLoader,
private parentRouter: Router,
@Attribute('name') nameAttr: string,
private _nav: Nav
) {
super(_elementRef, _loader, _parentRouter, nameAttr);
super(elementRef, loader, parentRouter, nameAttr);

// register this router with Ionic's NavController
// Ionic's NavController will call this NavRouter's "stateChange"
// method when the NavController has...changed its state
_nav.registerRouter(this);
}

activate(nextInstruction: ComponentInstruction): Promise<any> {
var previousInstruction = this['_currentInstruction'];
this['_currentInstruction'] = nextInstruction;
var componentType = nextInstruction.componentType;
var childRouter = this['_parentRouter'].childRouter(componentType);

// prevent double navigations to the same view
let instruction = new ResolvedInstruction(nextInstruction, null, null);
let url: string;
if (instruction) {
url = instruction.toRootUrl();
if (url === this._lastUrl) {
return Promise.resolve();
}
}

console.debug('NavRouter, activate:', componentType.name, 'url:', url);

// tell the NavController which componentType, and it's params, to navigate to
return this._nav.push(componentType, nextInstruction.params);
}

reuse(nextInstruction: ComponentInstruction) {
return Promise.resolve();
}

stateChange(direction: string, viewCtrl: ViewController) {
// stateChange is called by Ionic's NavController
// type could be "push" or "pop"
// viewCtrl is Ionic's ViewController class, which has the properties "componentType" and "params"

// only do an update if there's an actual view change
if (!viewCtrl) return;
if (!viewCtrl) {
return;
}

// get the best PathRecognizer for this view's componentType
let pathRecognizer = this.getPathRecognizerByComponent(viewCtrl.componentType);
Expand All @@ -89,17 +64,41 @@ export class NavRouter extends RouterOutlet {
}
}

activate(nextInstruction: ComponentInstruction): Promise<any> {
var previousInstruction = this['_currentInstruction'];
this['_currentInstruction'] = nextInstruction;
var componentType = nextInstruction.componentType;
var childRouter = this['_parentRouter'].childRouter(componentType);

// prevent double navigations to the same view
let instruction = new ResolvedInstruction(nextInstruction, null, null);
let url: string;
if (instruction) {
url = instruction.toRootUrl();
if (url === this._lastUrl) {
return Promise.resolve();
}
}

console.debug('NavRouter, activate:', componentType.name, 'url:', url);

// tell the NavController which componentType, and it's params, to navigate to
return this._nav.push(componentType, nextInstruction.params);
}

reuse(nextInstruction: ComponentInstruction) {
return Promise.resolve();
}

getPathRecognizerByComponent(componentType) {
// given a componentType, figure out the best PathRecognizer to use
let rules = this['_parentRouter'].registry._rules;
let rules = this.parentRouter.registry['_rules'];

let pathRecognizer = null;
rules.forEach((rule) => {

pathRecognizer = rule.matchers.find((matcherPathRecognizer) => {
return (matcherPathRecognizer.handler.componentType === componentType);
pathRecognizer = rule.rules.find(function(routeRule) {
return routeRule.handler.componentType === componentType;
});

});

return pathRecognizer;
Expand Down

0 comments on commit 3df5989

Please sign in to comment.