-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Aurelia Router should support ignoreUnknownRoutes
-like feature
#527
Comments
@PWKad A couple questions:
|
Right now the router hijacks any request that comes through when push state is active at the same base URL IIRC and the only way to allow the server to handle the request so the router doesn't swallow it is to map unknown routes and return a fake promise that never resolves, which is ugly. Instead the router should allow an option to not throw if a matching route isn't found which could be called something like |
@PWKad Thanks, your workaround works! 👍 If anyone is interested, I use the following piece of code inside my
|
I added a new PR as a work in progress to address this but as you mentioned it should fall through. https://github.com/aurelia/router/pull/561/files |
I guess #561 is not merged because of conflicts. |
@Alexander-Taran The issue was addressed and an issue was found in the PR so the work was reverted without ever being tested or worked on further, going to close this and other issues around the router to get the issues down. PushState is borderline unusable without a hacky workaround so I would advise not using pushstate unless you absolutely have to because it makes "embedding" your aurelia app in to a larger server rendered app much more difficult. |
@PWKad #527 (comment) - but I need pushState. |
IMO, this should be solved in browser history via a new API on it. Could potentially be an API on abstract class class History {
ignore(...routes: string[]): void;
} So when History implementation detects any changes that falls within ignore patterns, it simply ... ignores it and doesn't notify the router. |
Another option is to have an additional check in Lines 62 to 70 in 9ba6ef3
If there is a config for Something like this loadUrl(url: string): Promise<NavigationInstruction> {
+ if (this.ignoreUnknownRoutes) {
+ if (!this._recognizer.recognize(url) && !this._childRecognizer.recognize(url)) {
+ return Promise.resolve(null);
+ }
+ }
return this
._createNavigationInstruction(url)
.then(instruction => this._queueInstruction(instruction))
.catch(error => {
logger.error(error);
restorePreviousLocation(this);
});
} Thoughts? @EisenbergEffect @davismj @fkleuver @jwx |
@bigopon I don't think I agree that it should be added to |
@jwx Without touching the lovely details of routing of ignoreUnknownRoutes(pattern: Array<Regex | ((route: string) => boolean)>): void; Then in user code, probably just supply some manual process: configureRouter(config: RouterConfiguration, router: Router) {
config.ignoreUnknownRoutes([ /\*pdf$/ ]);
// or
config.ignoreUnknownRoutes([ route => route.indexOf('.pdf') !== -1 ]);
} |
@bigopon I PR'd almost that same code a year and a half ago - https://github.com/aurelia/router/pull/561/files - to I would recommend getting Matthews buy-in first before working on anything so you don't end up wasting your time to have it rejected later ;) I'm not going to close this issue again just to have it re-opened or whatever but I am going to unsubscribe so please don't @ me ;) |
@PWKad thanks for the reminder. There are some small differences between 2 versions, The earlier tries to create an instruction, and then check if it should proceed. The later tries to check if it should proceed before trying to create an instruction. I would say the later is safer and less side-effect prone. |
for more context: #558 I'm all for it! It just didn't work. I tried the code but it wouldn't let me download a file from the server. |
"it just didn't work" - yes it did, I don't appreciate your first comment after a year and a half of saying you wanted to wait until you could test it more being that it didn't work. I asked you not to revert the PR. |
The router for Durandal included an option to ignoreUnknownRoutes IIRC. If a link is clicked on and Aurelia doesn't have a matching route the request should be able to continue on to the server by having Aurelia completely ignore unknown routes.
Perhaps this could take a function to override the default behavior so the user can configure more thoroughly.
The text was updated successfully, but these errors were encountered: