#yew-router #yew #router #nested #web #html

yew-nested-router

A router for Yew which supports nesting

17 releases (7 breaking)

new 0.7.0-alpha.1 Apr 18, 2024
0.6.3 Jan 25, 2024
0.6.1 Dec 19, 2023
0.5.0 Nov 23, 2023
0.1.0 Dec 16, 2022

#786 in Web programming

Download history 24/week @ 2023-12-22 74/week @ 2023-12-29 256/week @ 2024-01-05 328/week @ 2024-01-12 397/week @ 2024-01-19 423/week @ 2024-01-26 407/week @ 2024-02-02 300/week @ 2024-02-09 309/week @ 2024-02-16 390/week @ 2024-02-23 445/week @ 2024-03-01 261/week @ 2024-03-08 221/week @ 2024-03-15 54/week @ 2024-03-22 318/week @ 2024-03-29 201/week @ 2024-04-05

813 downloads per month
Used in 2 crates

Apache-2.0

43KB
818 lines

Yew Nested Router

crates.io docs.rs

A router for Yew that supports nesting.

Example

In a nutshell, you define a main router entry point (<Router<T>>) where you can switch the rendering (<Switch<T>>). You can then translate down to the next layer (Scope<P, C>), so that you can switcher rendering again (Switch<C>).

See a complete example: examples/yew-nested-router-example, which you can run using:

trunk serve examples/yew-nested-router-example/index.html

Rationale

This project was born out of the need for a nesting router using Yew. This used to work in past releases, but starting with 0.19, the router implementation was swapped out for a new one which didn't properly support nesting. It still was possible to backport the old router to Yew 0.19, using the Yew Agent project.

However, in Yew Agent 0.2, which is required by Yew 0.20, the "context" agent was removed. So it was no longer possible to backport the old router implementation.

This is a new, from scratch, implementation of a router for Yew. It supports nesting, and using Rust types for routes.

Goals and opinions

This is not a drop-in replacement for the old Yew router. This section briefly describes which choices this implementation made:

  • The router supports a nested structured, where the child elements don't need to be aware of their parents. This is required in many cases, where one want to re-use lower level routes on different top level routes.
  • Routes are not defined by regular expressions or other pattern matching, but by simply splitting the path of a URL using the forward slash (/) into segments.
  • The implementation should try to help avoiding mistakes by using Rust's type system. But it won't fully guard against all mistakes which can be made.

Dependencies

~12–16MB
~284K SLoC