I would like to route all requests to its corresponding controllers index method, e.g. localhost/Home/bar and localhost/Home/bar/baz should go to the Home controller Index() method. locahost/About/foo/bar/baz should route to the About controller's Index method etc.
The reason is that I use a client side router on each page which takes care of the "deeper" routes. I tried adding a routing rule to "catch all", i.e. {controller/*.}, but if I use it my RenderModel is null on my requests.
What is more suitable here, a custom content finder or route hijacking?
Please let me know if I need to elaborate anything. Thanks!
depends if you have specific custom routes or if you have undefined amount of custom routes.
My suggestion would be ContentFinder when you want to do specific stuff depending on a substring in the url and you know they are names of nodes.
Or maybe look at doing custom routing and add routes to the route table and then have a look at a custom UmbracoVirtualNodeRouteHandler implementation.
I would say undefined in this case. Or at least I would prefer to explicitly specify them.
Perhaps I can use the content finder to extract the controller fragment, e.g. Home, from the URL, then return the appropriate content? Then the default routing would trigger the corresponding view and controller with the default conventions, right (the Home view and controller in this case)?
yes that's what I would try to do. Build a content finder. Check the url for matching terms (node name or whatever you want) and then return the correct node in the content finder so that it gets rendered.
Route hijacking vs content finder
Hello,
I would like to route all requests to its corresponding controllers index method, e.g.
localhost/Home/bar
andlocalhost/Home/bar/baz
should go to theHome
controllerIndex()
method.locahost/About/foo/bar/baz
should route to theAbout
controller'sIndex
method etc.The reason is that I use a client side router on each page which takes care of the "deeper" routes. I tried adding a routing rule to "catch all", i.e.
{controller/*.}
, but if I use it myRenderModel
isnull
on my requests.What is more suitable here, a custom content finder or route hijacking?
Please let me know if I need to elaborate anything. Thanks!
Hi Filur,
depends if you have specific custom routes or if you have undefined amount of custom routes.
My suggestion would be ContentFinder when you want to do specific stuff depending on a substring in the url and you know they are names of nodes.
Or maybe look at doing custom routing and add routes to the route table and then have a look at a custom UmbracoVirtualNodeRouteHandler implementation.
Maybe have a look at this blog post to get familiar with the content finder: https://24days.in/umbraco-cms/2014/urlprovider-and-contentfinder/
Regards David
Hi David,
Thanks for the reply.
I would say undefined in this case. Or at least I would prefer to explicitly specify them.
Perhaps I can use the content finder to extract the controller fragment, e.g.
Home
, from the URL, then return the appropriate content? Then the default routing would trigger the corresponding view and controller with the default conventions, right (theHome
view and controller in this case)?Hi Filur,
yes that's what I would try to do. Build a content finder. Check the url for matching terms (node name or whatever you want) and then return the correct node in the content finder so that it gets rendered.
Regards David
Allright, thanks for the input David!
is working on a reply...