-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Added hook for alternative route matching. #2571
Added hook for alternative route matching. #2571
Conversation
I like the idea of route-matching plugability. I'm just no big fan of encapsulating this as a function - would much rather prefer a dedicated service for this so people can create AngularJS modules with an alternative implementation. This should make unit-testing easier as well. |
I'm not attached to any particular implementation. The key thing for me is Are you able to outline how this would work as a service. I'm still getting On 6 May 2013 06:23, Pawel Kozlowski notifications@github.com wrote:
|
Very interested in this. For what I had in mind, I'd be able to generate a JSON of all resourceful routes of my API server, and use it in a custom angular router to auto generate equivalent factories for resources. |
-1 This is the D.I. way. In fact if you refactored |
Overriding $route entirely could work, but this approach needs to be documented, so there is a clear path for people who need alternative routing logic. This is not at all obvious to people who do not have a thorough understanding of DI works. Who knew you could overide a service. However, there appears to be a bit more in there than switchRouteMatcher (40 lines of code). updateRoute (70 lines of code) seems to encapsulate the details of how the route service interacts with the rest of angular. It would be convinient not to have to reinvent, or copy and paste, this. Maybe this code could be moved elsewhere. Understanding all the details of how the router interacts with the rest of angular is a large barrier. To put things in perspective, I've done this so I can use one viewcontroller if an arguments is an integer, and another if the argument is a string. The key problem is that the current router is not flexible enough for all use cases and there is no clear way to overcome this except by maintaining a local fork of angular. I don't really follow you on the refactoring of ng-view. It is worth noting, for my case at least, that the current route provider handles 99% of the routing cases. All I am after is a simple way to get a bit more control over routing decisions. Having learn't what I've learnt from writing this patch, what I would instead do is modify the router so the route given to $routeProvider.when() could be a function, which would be called to process the route args and return the route. This of course does not give as much flexibilty as being able to override the entire route matcher, which from reading other pull requests around routing, I gather would be desirable. On 11/05/2013, at 1:47 AM, Pete Bacon Darwin notifications@github.com wrote:
|
Have you taken a look at ui-router: https://github.com/angular-ui/ui-router/wiki? It could provide you with an alternative? |
I've got a better plan Hoggle. #2834 |
This patch enables the user to replace the route matching logic (i.e. switchMatchRouter() ) with custom logic via a callback function.
It strikes me that no routing scheme will ever keep everyone happy. A pragmatic solution to this is to allow plugable routing logic. This is a fairly straightforward way to do this.
Any feedback will be appreciated.