-
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
Support @page
with custom route template on components
#16436
Comments
Proposed designEach [Route("/customers")]
[Route("/customers/{customerId}")]
public CustomerInfo : IComponent
{
...
} @rynowak is working on adding a Razor directive for this, so that Route template string formatsFor now, we don't need to support all Microsoft.AspNetCore.Routing-supported route template syntaxes. For example, we don't necessarily need For 0.1.0 it's sufficient if the only syntax we support is slash-separated segments of the form Runtime behaviorThe existing
That's it for 0.1.0. We can consider more advanced routing features in the future, but I think this covers the key scenarios while being conceptually quite self-contained. @danroth27 Do you agree it's OK to require all page components to declare |
I'm MVC you're not required to use the leading slash because it means something different, it's also a little more complicated. Examples:
For now I'm going to go with just requiring the leading slash. Everything else builds upon that. |
@rynowak Dan and I spoke with @javiercn about him implementing the runtime part of this, with you having already said you'd do the compile-time piece generating the If you were interested in doing the runtime part as well could you communicate with @javiercn about that? Otherwise you might both be working on it :) |
ok cool beans. |
The language support for this is in. |
@rynowak It would be nice if we expose the components in the assembly through an assembly level attribute in a similar fashion to how pages get discovered. |
Oh oops, yeah I forgot to add that. I'll do the needful. |
Does the assembly-level attribute help though? You'd still have to scan for other types that have |
Today, we are using Angular quite a lot to build reusable components (each component being used in a hand full of customer projects; I have seen similar practices at many ISVs). These components have different routes in different end products. Angular enables that by separating routing from component metadata. Maybe this is a use-case that you could consider for Blazor, too. Another important routing feature of Angular that we regularly use are route guards. We implement functions that are called when a route is activated. The function e.g. checks whether the navigation is possible (e.g. permission check). If it is not, we can redirect the user to a different route (e.g. proper error message). Another use-case for such functions is logging (e.g. write usage log based on navigation between routes). It would be nice to have similar functionality at some time in Blazor, too. |
Yeah, that's a good point. We can't rely on this, so we might as well not do it. We'll have to scan for types regardless. I think I had the same thought during dotnet/blazor#244 which lead to me leaving it out. In my addled state of mind I've become very suggestible. |
Fair enough |
@javiercn Optional route parameters (e.g., @page /MyComponentPath
@page /MyComponentPath/{optionalParam} |
* Updates the router component to scan for components within assemblies. * Parses the templates on `[Route]` in component instances and builds a route table that maps paths to components. * Uses the route table to map paths to components.
You should be able to specify the
@page
on a component with a custom route template to make that component routable with parameters, similar to what is supported in Razor Pages.The text was updated successfully, but these errors were encountered: