Skip to content

Commit

Permalink
update documentation with suggested changes again
Browse files Browse the repository at this point in the history
  • Loading branch information
sasacocic committed Dec 8, 2022
1 parent 66aa852 commit 001ce08
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
8 changes: 4 additions & 4 deletions website/docs/concepts/router.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ current URL and passes it to the `render` callback. The callback then decides wh
matched, the router navigates to the path with `not_found` attribute. If no route is specified, nothing is rendered, and
a message is logged to console stating that no route was matched.

The router components, e.g. `<Link />` and `<Switch />`, must be used in the [context](concepts/contexts.mdx)
of a Router provider like `<BrowserRouter />`. That means they must be wrapper in a router (children of `<Router/>`).
This is shown below.
Most of yew-router's components, in particular <Link /> and <Switch />, must be (grand-)children of one of the Router components
(e.g. `<BrowserRouter />`). You usually only need a single Router in your app, most often rendered immediately by your most top-level `<App />`
component. The Router registers a context, which is needed for Links and Switches to function. An example is shown below.

:::caution
When using `yew-router` in browser environment, `<BrowserRouter />` is highly recommended.
Expand Down Expand Up @@ -95,7 +95,7 @@ fn switch(routes: Route) -> Html {
fn app() -> Html {
html! {
<BrowserRouter>
<Switch<Route> render={switch} /> // <- depends on <BrowserRouter>
<Switch<Route> render={switch} /> // <- must be child of <BrowserRouter>
</BrowserRouter>
}
}
Expand Down
13 changes: 8 additions & 5 deletions website/versioned_docs/version-0.19.0/concepts/router.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ current URL and passes it to the `render` callback. The callback then decides wh
matched, the router navigates to the path with `not_found` attribute. If no route is specified, nothing is rendered, and
a message is logged to console stating that no route was matched.

The router components, e.g. `<Link />` and `<Switch />`, must be used in the [context](concepts/contexts.mdx)
of a Router provider like `<BrowserRouter />`. That means they must be wrapper in a router (children of `<Router/>`).
This is shown below.
Most of yew-router's components, in particular `<Link />` and `<Switch />`, must be (grand-)children of one of the Router components
(e.g. `<BrowserRouter />`). You usually only need a single Router in your app, most often rendered immediately by your most top-level `<App />`
component. The Router registers a context, which is needed for Links and Switches to function. An example is shown below.

When using `yew-router` in browser environment, `<BrowserRouter />` is recommended.
:::caution
When using `yew-router` in browser environment, `<BrowserRouter />` is highly recommended.
You can find other router flavours in the [API Reference](https://docs.rs/yew-router/).
:::

```rust
use yew_router::prelude::*;
Expand Down Expand Up @@ -90,7 +93,7 @@ fn switch(routes: &Route) -> Html {
fn app() -> Html {
html! {
<BrowserRouter>
<Switch<Route> render={Switch::render(switch)} /> // <- depends on <BrowserRouter>
<Switch<Route> render={Switch::render(switch)} /> // <- must be child of <BrowserRouter>
</BrowserRouter>
}
}
Expand Down
7 changes: 4 additions & 3 deletions website/versioned_docs/version-0.20/concepts/router.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ current URL and passes it to the `render` callback. The callback then decides wh
matched, the router navigates to the path with `not_found` attribute. If no route is specified, nothing is rendered, and
a message is logged to console stating that no route was matched.

Finally, you need to register one of the Router context provider components like `<BrowserRouter />`.
It provides location information and navigator to its children.
Most of yew-router's components, in particular `<Link />` and `<Switch />`, must be (grand-)children of one of the Router components
(e.g. `<BrowserRouter />`). You usually only need a single Router in your app, most often rendered immediately by your most top-level `<App />`
component. The Router registers a context, which is needed for Links and Switches to function. An example is shown below.

:::caution
When using `yew-router` in browser environment, `<BrowserRouter />` is highly recommended.
Expand Down Expand Up @@ -94,7 +95,7 @@ fn switch(routes: Route) -> Html {
fn app() -> Html {
html! {
<BrowserRouter>
<Switch<Route> render={switch} />
<Switch<Route> render={switch} /> // <- must be child of <BrowserRouter />
</BrowserRouter>
}
}
Expand Down

0 comments on commit 001ce08

Please sign in to comment.