-
Notifications
You must be signed in to change notification settings - Fork 2k
Routes with trailing /
don't resolve properly
#1075
Comments
This method is being invoke because the UI router is resolving this route as the articles.view state, and expecting a The Articles API is resolving correctly to the I think the only viable option is to redirect the user back to the articles.list state. I don't see a need to reconcile the trailing |
There is a FAQ entry with respect to trailing slashes, would it be appropriate to use the method that ui-router recommends ? |
I gave a quick try today at the recommended approach in the ui-router faq, and it did not seem directly applicable. May be some interference with the html5 mode, or with the abstract state, not quite sure at this point. I ended up with either double slashes, or the route with the slash working but not the one without the slash, etc. I suggest this should be tagged as a bug @codydaig |
@vaucouleur @jloveland What do you think of this approach? getArticle.$inject = ['$state', '$stateParams', '$timeout', 'ArticlesService'];
function getArticle($state, $stateParams, $timeout, ArticlesService) {
if ($stateParams.articleId) {
return ArticlesService.get({
articleId: $stateParams.articleId
}).$promise;
} else {
// ui-router state transitions need to be wrapped in async functions when used inside route resolves, thus the $timeout
$timeout(function() {
$state.go('articles.list');
});
}
} Or do you think we should reconcile trailing slashes at the application ($stateProvider) level? With this approach, we'd have to implement this on any routes that could have this potential issue. Then we'd have similar code throughout the router configurations. This might not be the most elegant solution. However, one benefit (other than it being very simple & low impact), is that we could put custom logic here to handle many different use cases; it ends up being very flexible. |
@jloveland @vaucouleur I'd like to continue the discussion here, to find a good solution to this bug. I'm not super impressed with the solution that I've proposed in the PR. See these comments for insight into what I've tried, and the issues I'm having.. See this branch for a better solution, that I can't seem to get working properly. Well, properly meaning I don't want to define a Let me know what you think, or if you have any ideas. Maybe I'm doing something completely wrong. @vaucouleur Is this similar to the solution you mentioned above, that you tried? |
Before a lot more work is done on this, I guess we should decide if we want to keep the trailing slashes, or remove them. |
Usually trailing slashes aren't in the URL, so I think we should go that way to be consistent with most other sites. |
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
routes for articles with trailing
/
should show articles, but doesn't..http://localhost:3000/articles/
see below:
The text was updated successfully, but these errors were encountered: