Hi - I was wondering if $.route does (or will) support partial route matches or "splats"? I have a project where I want to listen to a starter route, and based on the value of the route, load the appropriate controller which will then attach it's own route bindings. Something such as:
url.com or url.com/#!controllerName (default controller name specified)
would load the controller, then that controller might listen to additional routes such as
url.com/#!controllerName/:id and url.com/#!controllerName/:id/:action
Curious if this is possible currently, perhaps through a partial match, or if there is a best practice to follow that I could benefit from.
You'll need a main Routing Controller to create Controller instances based on the route. Then the other Controllers just listen to their own routes and react to them. I added some code in there to delete the other Controller, which you may or may not need.
I also have the Routing Controller listening to any possible splish or splash routes so you can go from #!splish/2 to #!splash/2/delete and the Splash Controller instance would be created and the handler for splash/:id/:action would fire. There is no partial route matching, so this is necessary.
Thank you very much for the response and fiddle sample, very nice! I was hoping to avoid having to define every possible route in the main route controller, and leave that up to the individual controllers to define, keeping that logic separated, and it seemed that a "splat" implementation, similar to what backbone has, would do the trick nicely. I'll implement this suggested method for now, and possibly refactor in the near future. Thank you again!
Leave a comment on korycunningham's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic