Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mention certain components must be children of Router #2913

Merged
merged 6 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions website/docs/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
12 changes: 8 additions & 4 deletions website/versioned_docs/version-0.19.0/concepts/router.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +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.

Finally, you need to register the `<Router />` component as a context.
`<Router />` provides session history information 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.

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 @@ -89,7 +93,7 @@ fn switch(routes: &Route) -> Html {
fn app() -> Html {
html! {
<BrowserRouter>
<Switch<Route> render={Switch::render(switch)} />
<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