Expand description

Provides routing faculties for the Yew web framework.

Contents

This crate consists of multiple types, some independently useful on their own, that are used together to facilitate routing within the Yew framework. Among them are:

  • RouteService - Hooks into the History API and listens to PopStateEvents to respond to users clicking the back/forwards buttons.
  • RouteAgent - A singleton agent that owns a RouteService that provides an easy place for other components and agents to hook into it.
  • Switch - A trait/derive macro that allows specification of how enums or structs can be constructed from Routes.
  • Router - A component connected to the RouteAgent, and is capable of resolving Routes to Switch implementors, so you can use them to render Html.
  • Route - A struct containing an the route string and state.
  • RouteButton & RouteLink - Wrapper components around buttons and anchor tags respectively that allow users to change the route.

State and Aliases

Because the History API allows you to store data along with a route string, most types have at type parameter that allows you to specify which type is being stored. As this behavior is uncommon, aliases using the unit type (()) are provided to remove the need to specify the storage type you likely aren’t using.

If you want to store state using the history API, it is recommended that you generate your own aliases using the define_router_state macro. Give it a typename, and it will generate a module containing aliases and functions useful for routing. If you specify your own router_state aliases and functions, you will want to disable the unit_alias feature to prevent the default () aliases from showing up in the prelude.

Features

This crate has some feature-flags that allow you to not include some parts in your compilation.

  • “default” - Everything is included by default.
  • “core” - The fully feature complete (“router”, “components”, “matchers”), but without unit_alias.
  • “unit_alias” - If enabled, a module will be added to the route and expanded within the prelude for aliases of Router types to their () variants.
  • “router” - If enabled, the Router component and its dependent infrastructure (including “agent”) will be included.
  • “agent” - If enabled, the RouteAgent and its associated types will be included.
  • “components” - If enabled, the accessory components will be made available.

Re-exports

pub use crate::route::RouteState;
pub use crate::router::RouterState;
pub use switch::Switch;

Modules

Routing agent.

Components that integrate with the route agent.

Module for matching route strings based on tokens generated from the yew_router_route_parser crate.

Prelude module that can be imported when working with the yew_router

Wrapper around route url string, and associated history state.

Router Component.

Service that interfaces with the browser to handle routing.

Parses routes into enums or structs.

Macros

Generates a module named router_state containing aliases to common structures within yew_router that deal with operating with Route and its state values as well as functions for rendering routes.

Type Definitions

Alias of HashMap<&'a str, String> that represent strings captured from a route.

Derive Macros

Implements the Switch trait based on attributes present on the struct or enum variants.