fix queries

This commit is contained in:
Evan Almloff committed 2023-06-01 11:09:51 -05:00
1 parent 2f473f7c97
commit 037a248ad9
294 files changed
+60706 -263

No files matched your search

-90
View File
@@ -1,91 +1 @@
use dioxus::prelude::*;
use dioxus_router::prelude::*;
fn main() {
dioxus_web::launch(App);
}
fn App(cx: Scope) -> Element {
use_router(
cx,
&|| RouterConfiguration::default(),
&|| {
Segment::content(comp(Home))
.fixed("blog", Route::content(comp(Blog)).nested(
Segment::content(comp(BlogList)).catch_all(
ParameterRoute::content::<PostId>(comp(BlogPost))
.name::<BlogPostName>()
)
))
.fixed("myblog", "/blog") // this is new
.fallback(comp(PageNotFound))
}
);
render! {
NavBar {}
Outlet {}
}
}
fn NavBar(cx: Scope) -> Element {
render! {
nav {
ul {
li { Link { target: named::<RootIndex>(), "Home" } }
li { Link { target: "/blog", "Blog" } }
}
}
}
}
fn Home(cx: Scope) -> Element {
render! {
h1 { "Welcome to the Dioxus Blog!" }
}
}
fn Blog(cx: Scope) -> Element {
render! {
h1 { "Blog" }
Outlet {}
}
}
fn BlogList(cx: Scope) -> Element {
render! {
h2 { "Choose a post" }
ul {
li { Link {
target: named::<BlogPostName>().parameter::<PostId>("1"),
"Read the first blog post"
} }
li { Link {
target: named::<BlogPostName>().parameter::<PostId>("2"),
"Read the second blog post"
} }
}
}
}
struct PostId;
struct BlogPostName;
fn BlogPost(cx: Scope) -> Element {
let route = use_route(cx).unwrap();
let post_id = route.parameter::<PostId>();
let post = post_id
.map(|id| id.to_string())
.unwrap_or(String::from("unknown"));
render! {
h2 { "Blog Post: {post}"}
}
}
fn PageNotFound(cx: Scope) -> Element {
render! {
h1 { "Page not found" }
p { "We are terribly sorry, but the page you requested doesn't exist." }
}
}
+5 -6
View File
@@ -1,21 +1,22 @@
# Overview
In this guide you'll learn to effectively use Dioxus Router whether you're
In this guide, you'll learn to effectively use Dioxus Router whether you're
building a small todo app or the next FAANG company. We will create a small
website with a blog, homepage, and more!
> To follow along with the router example, you'll need a working Dioxus app.
> Check out the [Dioxus book][db] to get started.
> Check out the [Dioxus book](https://dioxuslabs.com/docs/0.3/guide/en/) to get started.
> Make sure to add Dioxus Router as a dependency, as explained in the
> [introduction](../index.md).
## You'll learn how to
- Create routes and render "pages".
- Utilize nested routes, create a navigation bar, and render content for a
set of routes.
- Gather URL parameters to dynamically display content.
- Redirect your visitors wherever you want.
- Parse URL parameters to dynamically display content.
- Redirect visitors to different routes.
> **Disclaimer**
>
@@ -26,5 +27,3 @@ website with a blog, homepage, and more!
You can find the complete application in the [full code](./full-code.md)
chapter.
[db]: https://dioxuslabs.com/guide/
@@ -1,4 +0,0 @@
# Navigation Failures
Some specific operations can cause a failure within router operations. The
subchapters contain information on how the router lets us handle such failures.
@@ -1,62 +0,0 @@
# Named Navigation Failure
When using [named navigation](../navigation/name.md), the router runs into a
problem under these circumstances:
1. The name we try to navigate to is not contained within our routes.
2. The route we navigate to requires a parameter that we don't provide when
triggering the navigation.
> Users cannot directly interact with named navigation. If a named navigation
> failure occurs, your app (or the router) has a bug.
The router reacts to this problem differently, depending on our apps build kind.
## Debug
When running a debug build, the router will `panic` whenever it encounters an
invalid navigation. This ensures that we notice these problems when we are
testing our application.
## Release
When running a release build, the router can't just `panic`, as that would be a
horrible user experience. Instead, it changes to show some fallback content.
> You can detect if the router is in the named navigation failure handling state
> by [checking](../navigation/name.md#check-if-a-name-is-present) if the
> [`FailureNamedNavigation`] name is present.
The default fallback explains to the user that an error occurred and asks them
to report the bug to the app developer.
You can override it by setting the `failure_named_navigation` value of the
[`RouterConfiguration`].
```rust,no_run
# // Hidden lines (like this one) make the documentation tests work.
# extern crate dioxus;
# use dioxus::prelude::*;
# extern crate dioxus_router;
# use dioxus_router::prelude::*;
fn NamedNavigationFallback(cx: Scope) -> Element {
render! {
h1 { "Named navigation failure!" }
}
}
fn App(cx: Scope) -> Element {
use_router(
cx,
&|| RouterConfiguration {
failure_named_navigation: comp(NamedNavigationFallback),
..Default::default()
},
&|| Segment::empty()
);
render! {
Outlet { }
}
}
```
[`FailureNamedNavigation`]: https://docs.rs/dioxus-router-core/latest/dioxus_router_core/prelude/struct.FailureNamedNavigation.html
[`RouterConfiguration`]: https://docs.rs/dioxus-router/latest/dioxus_router/hooks/struct.RouterConfiguration.html
@@ -1,64 +0,0 @@
# Redirection Limit Failure
The router enforces a limit of 25 redirects during a single routing navigation.
This is done to prevent infinite loops. If your app breaches that limit, you
should reorganize its routes to reduce the number of redirects.
> Users cannot trigger a redirection. If the redirection limit is breached, your
> app (or the router) has a bug.
> The [`on_update`](../routing-update-callback.md) callback doesn't count
> towards the limit, and resets it. You may have 25 redirects, then add an other
> one via the callback, and then have another 25.
The router reacts to a breach differently, depending on our apps build kind.
## Debug
When running a debug build, the router will `panic` whenever the redirecion
limit is breached. This ensures that we notice these problems when we are
testing our application.
## Release
When running a release build, the router can't just `panic`, as that would be a
horrible user experience. Instead, it changes to show some fallback content.
> You can detect if the router is in the redirection limit failure handling
> state by [checking](../navigation/name.md#check-if-a-name-is-present) if the
> [`FailureRedirectionLimit`] name is present.
The default fallback explains to the user that an error occurred and asks them
to report the bug to the app developer.
You can override it by setting the `failure_redirection_limit` value of the
[`RouterConfiguration`].
```rust,no_run
# // Hidden lines (like this one) make the documentation tests work.
# extern crate dioxus;
# use dioxus::prelude::*;
# extern crate dioxus_router;
# use dioxus_router::prelude::*;
fn RedirectionLimitFallback(cx: Scope) -> Element {
render! {
h1 { "Redirection limit breached!" }
}
}
fn App(cx: Scope) -> Element {
use_router(
cx,
&|| RouterConfiguration {
failure_redirection_limit: comp(RedirectionLimitFallback),
..Default::default()
},
&|| Segment::empty()
);
render! {
Outlet { }
}
}
```
[`FailureRedirectionLimit`]: https://docs.rs/dioxus-router-core/latest/dioxus_router_core/prelude/struct.FailureRedirectionLimit.html
[`RouterConfiguration`]: https://docs.rs/dioxus-router/latest/dioxus_router/hooks/struct.RouterConfiguration.html
+11 -25
View File
@@ -1,41 +1,27 @@
# Introduction
Whether or not you are building a website, desktop app, or mobile app,
> If you are not familiar with Dioxus itself, check out the [Dioxus book](https://dioxuslabs.com/docs/0.3/guide/en/) first.
Whether you are building a website, desktop app, or mobile app,
splitting your app's views into "pages" can be an effective method for
organization and maintainability.
For this purpose, Dioxus provides a router. To start utilizing it, add it as a
dependency in your `Cargo.toml` file:
```toml
[dependencies]
# use this for native apps
dioxus-router = "*"
#use this for web apps
dioxus-router = { version = "*", features = ["web"] }
For this purpose, Dioxus provides a router. Use the `cargo add` command to add the dependency:
# in both cases replace * with the current version
```
You can also use the `cargo` command to add the dependency:
```sh
$ cargo add dioxus-router
$ cargo add dioxus-router --features web
cargo add dioxus-router
```
> If you are not familiar with Dioxus itself, check out the [Dioxus book][db]
> first.
This book is intended to get you up to speed with Dioxus Router. It is split
into two sections:
1. The [Features](./features/index.md) part explains individual features in
1. The [Reference](./reference/index.md) part explains individual features in
depth. You can read it start to finish, or you can read individual chapters
in whatever order you want.
2. If you prefer a learning-by-doing approach, you can check ouf the
_[example project](./example/introduction.md)_. It guides you through
2. If you prefer a learning-by-doing approach, you can check out the
_[example project](./example/index.md)_. It guides you through
creating a dioxus app, setting up the router and using some of its
functionality.
> Please note that this is not the only documentation for the Dioxus Router. You
> can also check out the [API Docs][api].
[api]: https://docs.rs/dioxus-router/
[db]: https://dioxuslabs.com/guide/
> can also check out the [API Docs](https://docs.rs/dioxus-router/).
+1
View File
@@ -0,0 +1 @@
// empty (we only need this crate for the examples)
@@ -1,3 +1,8 @@
# Navigation Failures
Some specific operations can cause a failure within router operations. The
subchapters contain information on how the router lets us handle such failures.
# External Navigation Failure
> This section doesn't apply when specifying a `target` on a [`Link`]. See the
@@ -13,6 +18,7 @@ This will only work in the browser, when using either [`WebHistory`] or
[`WebHashHistory`].
## Failure handling
When the router encounters an external navigation it cannot fulfill, it changes
the path to `/` and shows some fallback content.
@@ -14,7 +14,7 @@ forward buttons:
> If you want to navigate through the history programmatically, take a look at
> [`programmatic navigation`](./navigation/programmatic.md).
```rust,no_run
```rust, no_run
# // Hidden lines (like this one) make the documentation tests work.
# extern crate dioxus;
use dioxus::prelude::*;
@@ -6,15 +6,15 @@ functionality.
The router provides five [`HistoryProvider`]s, but you can also create your own.
The five default implementations are:
- The [`MemoryHistory`] is a custom implementation that works in memory.
- The [`WebHistory`] integrates with the browsers URL.
- The [`WebHashHistory`] also integrates with the browser, but uses the fragment
part of the URL.
By default the router uses the [`MemoryHistory`]. It might be changed to use
[`WebHistory`] when the `web` feature is active, but that is not guaranteed.
You can override the default history:
```rust,no_run
# // Hidden lines (like this one) make the documentation tests work.
# extern crate dioxus;
@@ -41,4 +41,3 @@ fn App(cx: Scope) -> Element {
[`HistoryProvider`]: https://docs.rs/dioxus-router-core/latest/dioxus_router_core/history/trait.HistoryProvider.html
[`MemoryHistory`]: https://docs.rs/dioxus-router-core/latest/dioxus_router_core/history/struct.MemoryHistory.html
[`WebHistory`]: https://docs.rs/dioxus-router-core/latest/dioxus_router_core/history/struct.WebHistory.html
[`WebHashHistory`]: https://docs.rs/dioxus-router-core/latest/dioxus_router_core/history/struct.WebHashHistory.html
File renamed without changes.
File renamed without changes.
File renamed without changes.