update the router guide
This commit is contained in:
1 parent
67992f7da9
commit
0d3ea377ce
63 files changed
+615
-1705
No files matched your search
@@ -15,7 +15,8 @@ the [`Link`] component is more convenient to use, as it automatically sets the
|
||||
`rel` attribute for the link, when the target is external.
|
||||
|
||||
## Code Example
|
||||
```rust
|
||||
|
||||
```rust, no_run
|
||||
# // Hidden lines (like this one) make the documentation tests work.
|
||||
# extern crate dioxus;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
@@ -9,6 +9,7 @@ like this:
|
||||
```
|
||||
|
||||
However, we cannot do that when using the router for two reasons:
|
||||
|
||||
1. Anchor tags make the browser load a new page from the server. This takes a
|
||||
lot of time, and it is much faster to let the router handle the navigation
|
||||
client-side.
|
||||
@@ -17,7 +18,8 @@ However, we cannot do that when using the router for two reasons:
|
||||
|
||||
To solve these problems, the router provides us with a [`Link`] component we can
|
||||
use like this:
|
||||
```rust,no_run
|
||||
|
||||
```rust, no_run
|
||||
# // Hidden lines (like this one) make the documentation tests work.
|
||||
# extern crate dioxus;
|
||||
# use dioxus::prelude::*;
|
||||
@@ -40,6 +42,7 @@ fn SomeComponent(cx: Scope) -> Element {
|
||||
The `target` in the example above is similar to the `href` of a regular anchor
|
||||
element. However, it tells the router more about what kind of navigation it
|
||||
should perform:
|
||||
|
||||
- The example uses [`Internal`]. We give it an arbitrary path that will be
|
||||
merged with the current URL.
|
||||
- [`Named`] allows us to navigate within our app using predefined names.
|
||||
|
||||
@@ -11,6 +11,7 @@ automatically create the actual path to navigate to, even inserting required
|
||||
parameters.
|
||||
|
||||
_Named_ navigation has a few advantages over _path-based_ navigation:
|
||||
|
||||
- Links can be created without knowing the actual path.
|
||||
- It is much easier to find all links to a specific route.
|
||||
- The router knows what links are invalid (and will panic in debug builds).
|
||||
@@ -27,7 +28,8 @@ _Named_ navigation has a few advantages over _path-based_ navigation:
|
||||
> certain conditions. None of these names can be used for app defined routes.
|
||||
|
||||
## Code Example
|
||||
```rust
|
||||
|
||||
```rust, no_run
|
||||
# // Hidden lines (like this one) make the documentation tests work.
|
||||
# extern crate dioxus;
|
||||
use dioxus::prelude::*;
|
||||
@@ -90,11 +92,12 @@ fn App(cx: Scope) -> Element {
|
||||
```
|
||||
|
||||
## Check if a name is present
|
||||
|
||||
You can check if a specific name is present for the current route. This works
|
||||
similar to getting the value of a [parameter route](../routes/parameter.md) and
|
||||
the same restrictions apply.
|
||||
|
||||
```rust,no_run
|
||||
```rust, no_run
|
||||
# // Hidden lines (like this one) make the documentation tests work.
|
||||
# extern crate dioxus;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
@@ -4,10 +4,11 @@ Sometimes we want our application to navigate to another page without having the
|
||||
user click on a link. This is called programmatic navigation.
|
||||
|
||||
## Acquiring a [`Navigator`]
|
||||
|
||||
To use programmatic navigation, we first have to acquire a [`Navigator`]. For
|
||||
that purpose we can use the [`use_navigate`] hook.
|
||||
|
||||
```rust,no_run
|
||||
```rust, no_run
|
||||
# // Hidden lines (like this one) make the documentation tests work.
|
||||
# extern crate dioxus;
|
||||
use dioxus::prelude::*;
|
||||
@@ -23,7 +24,9 @@ fn Content(cx: Scope) -> Element {
|
||||
```
|
||||
|
||||
## Triggering a Navigation
|
||||
|
||||
We can use the [`Navigator`] to trigger four different kinds of navigation:
|
||||
|
||||
- `push` will navigate to the target. It works like a regular anchor tag.
|
||||
- `replace` works like `push`, except that it replaces the current history entry
|
||||
instead of adding a new one. This means the prior page cannot be restored with
|
||||
@@ -32,7 +35,7 @@ We can use the [`Navigator`] to trigger four different kinds of navigation:
|
||||
- `Go forward` works like the browsers forward button (the opposite of the back
|
||||
button).
|
||||
|
||||
```rust,no_run
|
||||
```rust, no_run
|
||||
# // Hidden lines (like this one) make the documentation tests work.
|
||||
# extern crate dioxus;
|
||||
# use dioxus::prelude::*;
|
||||
@@ -64,6 +67,7 @@ You might have noticed that, like [`Link`], the [`Navigator`]s `push` and
|
||||
[`Internal`], [`Named`] and [`External`].
|
||||
|
||||
## External Navigation Targets
|
||||
|
||||
Unlike a [`Link`], the [`Navigator`] cannot rely on the browser (or webview) to
|
||||
handle navigation to external targets via a generated anchor element.
|
||||
|
||||
|
||||
Reference in new issue
Block a user