Blazor Routing in depth
Автор: Babu Tech Programmer
Загружено: 2018-05-17
Просмотров: 1082
Описание:
What is Blazor routing?
Routing in blazor is the way by which a user request is responded by blazor component based on the url request. Like other routing framework in blazor you have to define the route and then we can use the route. In blazor component is the building block. So here we have to declare the routing in the component. This routing is then can be used to discover the component or to redicrect to the route.
Rout can be define in two ways,
suppose your creating the component as .cshtml then we can use the @page “rout” it is similar to routing in razor pages.
If your creating the component using .cs files means coding, then we have to declare the rout as RoutAttribute.
Once the route is defined we have to trigger routing framework. That part id done partially in the App.cshtml it temporary, in future the experience of doing this will be more seamless, may be like in Mvc, in blazor .UseBlazorRout().
Passing parameter in rout url and getting the value
route parameter is declare like @page “/{routparameter}” and we have to declare a property of type string to get the parameter value.
Note: there is no concept of optional parameter concept in current release of Blazor. If you want to achieve the optional parameter functionality then we have to declare two routes one with parameter other with non parameter.
Routing programmatically:-
this is another common scenario in web which allows us to programmatically redirect to other component.
Suppose take our todo application example. In here when the user clicks the the create button if the insert of data is success then we just want to redirect the user to the todo list page. To do this we have to take the help of dependency injection and inject IurilHelper interface.
@inject Microsoft.Aspnetcore.Blaazor.services.IuriHelper uriHelper.
Then in the code we can call uriHelper.Navigateto(“uri”);
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: