Skip to content

Commit

Permalink
update nested router docs (#2535)
Browse files Browse the repository at this point in the history
* update nested router docs

* !!!

* fix according to comments

* fix error
  • Loading branch information
voidpumpkin authored Mar 20, 2022
1 parent b9bd18f commit 5ececa4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
34 changes: 20 additions & 14 deletions website/docs/concepts/router.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -398,24 +398,32 @@ digraph {
-->

import useBaseUrl from "@docusaurus/useBaseUrl";
import ThemedImage from '@theme/ThemedImage';
import ThemedImage from "@theme/ThemedImage";

<ThemedImage
alt="nested router structure"
sources={{
light: useBaseUrl('/img/nested-router-light.svg'),
dark: useBaseUrl('/img/nested-router-dark.svg'),
}}
alt="nested router structure"
sources={{
light: useBaseUrl("/img/nested-router-light.svg"),
dark: useBaseUrl("/img/nested-router-dark.svg"),
}}
/>

The nested `SettingsRouter` handles all urls that start with `/settings`. Additionally, it redirects urls that are not
matched to the main `NotFound` route. So `/settings/gibberish` will redirect to `/404`.

:::caution

Though note that this is still work in progress so the way we do this is not final

:::

It can be implemented with the following code:

```rust
use yew::prelude::*;
use yew_router::prelude::*;
use gloo::utils::window;
use wasm_bindgen::UnwrapThrowExt;

#[derive(Clone, Routable, PartialEq)]
enum MainRoute {
Expand All @@ -425,7 +433,9 @@ enum MainRoute {
News,
#[at("/contact")]
Contact,
#[at("/settings/:s")]
#[at("/settings")]
SettingsRoot,
#[at("/settings/*")]
Settings,
#[not_found]
#[at("/404")]
Expand All @@ -434,7 +444,7 @@ enum MainRoute {

#[derive(Clone, Routable, PartialEq)]
enum SettingsRoute {
#[at("/settings/profile")]
#[at("/settings")]
Profile,
#[at("/settings/friends")]
Friends,
Expand All @@ -450,9 +460,7 @@ fn switch_main(route: &MainRoute) -> Html {
MainRoute::Home => html! {<h1>{"Home"}</h1>},
MainRoute::News => html! {<h1>{"News"}</h1>},
MainRoute::Contact => html! {<h1>{"Contact"}</h1>},
MainRoute::Settings => html! {
<Switch<SettingsRoute> render={Switch::render(switch_settings)} />
},
MainRoute::SettingsRoot | MainRoute::Settings => html! { <Switch<SettingsRoute> render={Switch::render(switch_settings)} /> },
MainRoute::NotFound => html! {<h1>{"Not Found"}</h1>},
}
}
Expand All @@ -462,9 +470,7 @@ fn switch_settings(route: &SettingsRoute) -> Html {
SettingsRoute::Profile => html! {<h1>{"Profile"}</h1>},
SettingsRoute::Friends => html! {<h1>{"Friends"}</h1>},
SettingsRoute::Theme => html! {<h1>{"Theme"}</h1>},
SettingsRoute::NotFound => html! {
<Redirect<MainRoute> to={MainRoute::NotFound}/>
}
SettingsRoute::NotFound => html! {<Redirect<MainRoute> to={MainRoute::NotFound}/>}
}
}

Expand Down
6 changes: 0 additions & 6 deletions website/static/img/nested-router-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions website/static/img/nested-router-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit 5ececa4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yew master branch benchmarks (Lower is better)

Benchmark suite Current: 5ececa4 Previous: b9bd18f Ratio
yew-struct-keyed 01_run1k 241.6995 157.02800000000002 1.54
yew-struct-keyed 02_replace1k 239.7065 182.452 1.31
yew-struct-keyed 03_update10th1k_x16 347.4445 318.45349999999996 1.09
yew-struct-keyed 04_select1k 84.5815 64.5195 1.31
yew-struct-keyed 05_swap1k 93.749 84.161 1.11
yew-struct-keyed 06_remove-one-1k 30.2355 27.662 1.09
yew-struct-keyed 07_create10k 2774.7185 2040.951 1.36
yew-struct-keyed 08_create1k-after1k_x2 542.986 369.944 1.47
yew-struct-keyed 09_clear1k_x8 238.669 193.878 1.23
yew-struct-keyed 21_ready-memory 0.9634475708007812 0.9634475708007812 1
yew-struct-keyed 22_run-memory 1.45648193359375 1.4979515075683594 0.97
yew-struct-keyed 23_update5-memory 1.4602203369140625 1.4602203369140625 1
yew-struct-keyed 24_run5-memory 1.5095291137695312 1.5095291137695312 1
yew-struct-keyed 25_run-clear-memory 1.1243438720703125 1.1272430419921875 1.00
yew-struct-keyed 31_startup-ci 1789.45 1732.042 1.03
yew-struct-keyed 32_startup-bt 37.67799999999999 33.303999999999995 1.13
yew-struct-keyed 34_startup-totalbytes 330.5498046875 330.5498046875 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.