-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(core): Remove trailing slash from routes #1238
Conversation
@jloveland @vaucouleur How does this solution seem to you? My fix assumes that we want to remove the trailing slash. However, maybe that's not the desired behavior? As I was exploring possible solutions, I didn't see a straight forward way of keeping the trailing slash, but resolving to the correct client route. I don't see a good reason to keep the slash. |
f41a25c
to
ef30bef
Compare
I'm a lot happier with this solution. We can define a $urlRouterProvider Rule that removes the trailing slashes from the URL, and it applies to all routes. The Rule is only defined once, in the Core module route configuration. In order for this to work, we have to load the Core module routes into the angular app, before we load any other routes. This required a change to the @jloveland @vaucouleur @ilanbiala Review? |
The code seems pretty good. 👍 |
@rhutchison pointed out that we can avoid manually ensuring that the Core module loads first; with my changes to the |
ef30bef
to
17f72e4
Compare
@codydaig @ilanbiala @rhutchison LGTY? |
LGTM. |
@@ -1,7 +1,7 @@ | |||
(function (app) { | |||
'use strict'; | |||
|
|||
app.registerModule('articles'); | |||
app.registerModule('articles', ['core']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mleanos should we add a comment above this line to indicate core is required to provide deterministic order..forcing core to load first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't sound like a bad idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this forces Core to load first though. I know my wording above indicates that it does. But now that I think about it, all this does is add Core as a dependency; it's sort of ambiguous as to whether Core is indeed loading first, or not.
Perhaps a comment more along the lines of Core being required for special route handling? This aspect of module dependency feels weird to me. But I guess it's the intention of Angular's module dependency injection. I really feel like we should be able to tell Angular to load Core first, or into each module. Rather than injecting it into every single module definition. However, I guess that's a bit off topic :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your suggestion..something like "Core module is required for special route handling"
I am not sure either about the module loading order, from the docs it describes how modules are asynchronously loaded:
Because modules do nothing at load time they can be loaded into the VM in any order and thus script loaders can take advantage of this property and parallelize the loading process.
but then, the docs describe how dependencies are loaded first:
Modules can list other modules as their dependencies. Depending on a module implies that the required module needs to be loaded before the requiring module is loaded. In other words the configuration blocks of the required modules execute before the configuration blocks of the requiring module.
@mleanos one thing I noticed is that trying to navigate to a bad route on articles doesn't give a |
@jloveland I'll look into that in a bit. There's probably a console error in the browser. If so, what is it? |
Actually, just checked on the master branch, and I'm seeing the same behavior. No console errors, but the server is returning a 400 response, because of the invalid articleId param ("foo"). I'll see if there's an easy fix. It seems like a good idea to add a fix for that to this PR. WDYT? |
Seems like fixing the articles invalid article param would be small enough to be included here.. |
17f72e4
to
35c9208
Compare
@ilanbiala @jloveland I added the comment to just the Articles client module. I think this is where it's more applicable, and generally users will use Articles to base their other modules off of. To fix the invalid ArticleId issue, I added a new service for implementing $http interceptors for 400 & 404 server errors. Let me know if this looks good to you; I partly feel this should be in it's own PR, but if you're all happy then I don't think it's a huge deal (just more to review). |
Adds an angular $urlRouterProvider service Rule to the Core module configuration, that removes any trailing slashes in the URL for all routes. The Rule is defined in the core routes configuration. Thus, in order for this to work on all routes in the application, we have to inject the Core module into each client module, as a dependecy in the client.module configuration. Otherwise, we'd have to define the Rule in each module's route configuration individually. Adds missing client-side route configuration tests. Tests demonstrate that the various route configurations can handle a trailing slash in the URL, and gets resolved to the correct client route. Fixes meanjs#1075
35c9208
to
b004986
Compare
I reverted the commit with the $http Interceptors. I forgot why we hadn't implemented them for 404 & 400 already. We're sending back 400 & 404 error responses from the server, where we don't want to redirect the user. It's going to be a bit more involved to fix this issue. I'd rather tackle that in a separate issue, and PR. @ilanbiala @jloveland SGTY? |
SGTM |
LGTM |
Merging since all the feedback has been addressed. |
fix(core): Remove trailing slash from routes
Prevents transitioning to a URL with a trailing slash.
If a trailing slash is found in the transitioning URL, then the transition is aborted & the user is redirected to the path without the trailing slash.
Adds missing client-side route configuration tests.
Demonstrates that the various route configurations can handle a trailing slash in the URL, and resolve to the correct client route.
Fixes #1075