Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/ignore unknown routes #561

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -110,7 +110,7 @@
"yargs": "^4.8.1"
},
"peerDependencies": {
"aurelia-history": "^1.1.0",
"aurelia-history": "^1.1.0"
},
"aurelia": {
"documentation": {
Expand Down
15 changes: 10 additions & 5 deletions src/app-router.js
Expand Up @@ -41,12 +41,17 @@ export class AppRouter extends Router {
*/
loadUrl(url): Promise<NavigationInstruction> {
return this._createNavigationInstruction(url)
.then(instruction => this._queueInstruction(instruction))
.catch(error => {
if (!this.ignoreUnknownRoutes) {
logger.error(error);
restorePreviousLocation(this);
.then(instruction => {
if (!instruction && this.ignoreUnknownRoutes) {
this.history.navigate(url, {trigger: true});
window.location.pathname = url;
} else {
this._queueInstruction(instruction);
}
})
.catch(error => {
logger.error(error);
restorePreviousLocation(this);
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/router.js
Expand Up @@ -511,7 +511,9 @@ export class Router {
return evaluateNavigationStrategy(instruction, router.catchAllHandler);
}
}

if (this.ignoreUnknownRoutes) {
return Promise.resolve(false);
}
return Promise.reject(new Error(`Route not found: ${url}`));
}

Expand Down