-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested Routing In Blazor #11212
Comments
Yep, this is essential for larger applications - and enables something like 'feature modules' (as we have in Angular). |
I would like to second this request. Right now the router is meant as a single central thing that controls the routing of the whole application but this is actually a very special case. It would help a lot if you could create relative routers that will just route relatively to wherever they currently are, regardless of whether you create an SPA or whether your (server-side) Blazor app is a component on a normal server-side Razor view. I took a deeper look at the routing components and I think what conflicts this idea the most at the moment is that the Other frameworks, e.g. Angular’s router, solve this by actually having routes declared at the router, instead of automatically discovering routes through the components. So what would be helpful if there was a way to provide a router with a already prepared [edit] Okay, this fails because all the useful things are internal, like |
@danroth27 @SteveSandersonMS |
It would be great to have component->component routing. currently routing only works for pages (i.e: controllers). I would love to have a tag and have routing within that component that can load other components based on the url. Even something like <component_router><root_component/></component_router>would be ok and we register routes to components somehow. The only way to currently do this is a root component that essentially is a giant switch to determine the state and swapout the components as required. Imagine a simple crud component. It may have to be embedded into an existing razor view due to a legacy enterprise app written with Controllers & Views (the main selling point for blazor-server). It is easier to maintain and manage 3 or 4 smaller components dedicated to the task than one component with a huge bunch of razor logic to determine the presentation. |
Hi, If anyone comes across this thread I have created BlazorCrudComponentRouter that enables you to easily create a CRUD based razor component to make it easier to host within MVC Views. This achieves my goal for the short term when slowly moving away from MVC Controllers & Views in 2.1 to 3.1 hosted razor components (Blazor Server). Your main razor component then looks like this:
Maybe useful for other people so it's MIT licensed until Blazor supports component based routing (if it ever will) |
Child or nested (relative) routing is very much a needed feature similar to what Angular offers but i don't see any significant progress on its availability. Is there any plans for this feature to come out soon? |
Hi,
I just built a production sit in blazor server. It is production ready.
However if you want a hybrid then yes you would need my component.
I just deployed my project to production so will try to give you what you
need this Sunday.
…On Thu, 16 Apr 2020, 7:31 pm Furqan Safdar, ***@***.***> wrote:
It is very much needed for my experimental project on Blazor to see its
readiness for production but i don't see any significant progress on the
availability of this feature.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#11212 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACUJ2HM452XRXUL2EROE4PLRM3JODANCNFSM4HYFOZEQ>
.
|
现在的路由功能太简陋了,希望能像angular一样。 |
I support the request for nested routing. Being able to provide "Deep" links into an application is critical. MySite.Com\customer\123\order\45\orderitem\6 |
@kevoh That’s already possible with the existing router. |
Hi @SteveSandersonMS. Can you please share some links which explain how to achieve what kevonh asks? I'm learning Blazor and I don't find anything related. Thanks |
@titobf Blazor's routing system lets you accept any number of parameters. For example you could declare a route template like:
Please see docs at https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing?view=aspnetcore-3.1#route-parameters |
Hi @SteveSandersonMS, I think what this is about is having a routing system similar to Angular or react-router, where CustomerComponent.razor: And inside CustomerComponent we have some sort of route config:
|
Yes, I know :) It is something we’d like to do. I was just answering the question to give a way of achieving the desired route pattern with the existing router features. |
This, exactly! Up vote++ |
Has there been any work done on this feature? |
Not in 5.0. We have focused on many other priorities. I hope it makes sense that we have to balance a lot of different priorities and customer demands. If you're keen to advocate for this as a 6.0 feature, the most effective way to advocate for it would be describing clear and simple scenarios where you think this is needed and why the existing routing system isn't sufficient. For example, why there's a practical problem with declaring route patterns like I'm not arguing that anyone is wrong, so please don't interpret it that way :) I'm just saying that having clearer explanations will help to make a stronger case for why this needs to be prioritised above other enhancements that are also being demanded. Hope that makes sense! |
@SteveSandersonMS I'm a man of a few words so I'm gonna give you an example. Please take a look at this (see Profile tab) How can we do something similar in Blazor. We are building an larger app and something like this is a must have. Currently we have somekind of hacks like CrudComponentRouter with history.replaceState but that is extremely dirty. |
It looks like something like this can also be done with nested layouts. But I don't think razor file currently supports specifying a layout file like cshtml does. |
Actually, it looks like nested layouts work in razor file as well. |
Layouts work but imagine the following example. Based on the route you need to dynamically add tab item into tab control. After a tab item is added it should render some component as it's content. The newly added tab item should have it's set of routes that change just the rendered content of the tab item component. |
@partyelite I'm facing a similar issue. Did you find any solution? Working with tabs and routes with Blazor seems a little complicated. This is a reason to see this feature implemented. |
@knuxbbs sorry, no.. I have tried using javascript for routing inside tabs but that proved to be unreliable because of the bugs in browsers (like firefox not replacing url when pushState is used).. |
For folks that are interested in this feature, have you tried https://github.com/hez2010/BlazorRouter? How well does it meet your needs? |
I don't think it implements nested routing as most people would understand it. angulars router (would be my preferred method) allows multiple active components (or routes) at the same time. Essentially it builds a stack of matched routes (from a tree structure) and router-outlets will render that stack. |
No, that "nested routing" in the referenced project is not a real routing. Technically it is just a nested switch/case statement in Razor syntax. A real nested routing would allow to configure a component to listen on a defined part of the url or a query parameter, i.e. either by code or by simple configuration. The latter is important because currently there is absolutely no way to share the pages (standard Blazor) or components with routing information (BlazorRouter) between different projects where each project needs to define different routes for the same pages / components. This is also especially important for the already mentioned tab-use case (which tab is selected). This, by the way, also requires a two-way binding from the route back to the url, so if you switch the tab the url needs to reflect that change to allow the standard web feature of deep linking to work. Also, the distinction between Pages (which allow to bind a property to a query parameter) and components (where this is not possible) is very strange. There should be only components with all possible binding features and if a component can be routed to (if it is a Page) should be defined in the application startup when the router is configured. |
IIRC internally there's no "Page" - it's just a component with an specific attribute attached, that defines the route. If you have access to the route-table (unfortunately this is internal), you can add components as pages. |
You'd need to derive from a component in a shared library without the attribute it in each project just to add the attribute to it on the derived class. This is really unfortunate and a really bad developer experience. You should not be forced to derive from a type just to define a route with an attribute. |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
Any update on this? |
@mkArtakMSFT Any news on this feature? Can we now when do you plan do deploy this ? |
@rborosak @malieop This issue is currently in our Backlog milestone, which means it's not currently committed for any upcoming release. If folks in the community have specific thoughts on the key scenarios it should enable, design proposals on how it should work, or implementation approaches, we welcome these contributions. |
Just chiming in to express my strong desire for this feature. Alternatively, if RouteTableFactory was more extensible, that would also be good. |
@SteveSandersonMS As 5489 is closed now.
Can we put nested routing on the roadmap as it is necessary feature for routing
Ref. Angular Router Outlet
The text was updated successfully, but these errors were encountered: