Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hez2010/BlazorRouter

An awesome router for blazor.
https://github.com/hez2010/BlazorRouter

Last synced: about 2 months ago
JSON representation

An awesome router for blazor.

Awesome Lists containing this project

README

        

# BlazorRouter [![nuget](https://img.shields.io/nuget/vpre/Hez2010.BlazorRouter.svg)](https://www.nuget.org/packages/Hez2010.BlazorRouter)
An awesome router for blazor inspired by react-router, providing declarative routing for Blazor.

## Installation
Via nuget package:
```
dotnet add package Hez2010.BlazorRouter
```
Then append `@using BlazorRouter` to your `_Imports.razor`

## Usage
Put `` to the place where you want to route your contents.
Then use `` to config routing template with `Template` property.
In the end, you can put the routed content inside the ``.

Parameters in the routing template will be passed as `IDictionary` with attribute `[CascadingParameter(Name = "RouteParameters")]`.

The order of routing is from the top to the bottom in ``, and it will use the first matched item.
If `Template` was not defined or defined as empty, it will match any path.

For example:
```html














404


```

Besides, you can nest `Switch` to use nested routing:

For example:
```html



















404 in /user/id






404


```

`*` represents one (can be zero if it's the last segment in template) segment, and you can use `**` to match multiple segments (>= 0).

Note: `**` can only be the last segment.

```html

















404


```

## Live Example
[Visit Sample](https://hez2010.github.io/BlazorRouter)
For source, please check out `BlazorRouter.Sample`.