-
-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into url-encode-routes
- Loading branch information
Showing
29 changed files
with
426 additions
and
491 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "query_segments_demo" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
dioxus = { path = "../../packages/dioxus", version = "*" } | ||
dioxus-router = { path = "../../packages/router", version = "*" } | ||
dioxus-web = { path = "../../packages/web", version = "*" } | ||
form_urlencoded = "1.2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#![allow(non_snake_case, unused)] | ||
//! Example: Url query segments usage | ||
//! ------------------------------------ | ||
//! | ||
//! This example shows how to access and use multiple query segments present in an url on the web. | ||
//! | ||
//! Run `dx serve` and navigate to `http://localhost:8080/blog?name=John&surname=Doe` | ||
use std::fmt::Display; | ||
|
||
use dioxus::prelude::*; | ||
use dioxus_router::prelude::*; | ||
|
||
// ANCHOR: route | ||
#[derive(Routable, Clone)] | ||
#[rustfmt::skip] | ||
enum Route { | ||
// segments that start with ?: are query segments | ||
#[route("/blog?:query_params")] | ||
BlogPost { | ||
// You must include query segments in child variants | ||
query_params: BlogQuerySegments, | ||
}, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
struct BlogQuerySegments { | ||
name: String, | ||
surname: String, | ||
} | ||
|
||
/// The display impl needs to display the query in a way that can be parsed: | ||
impl Display for BlogQuerySegments { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "name={}&surname={}", self.name, self.surname) | ||
} | ||
} | ||
|
||
/// The query segment is anything that implements https://docs.rs/dioxus-router/latest/dioxus_router/routable/trait.FromQuery.html. You can implement that trait for a struct if you want to parse multiple query parameters. | ||
impl FromQuery for BlogQuerySegments { | ||
fn from_query(query: &str) -> Self { | ||
let mut name = None; | ||
let mut surname = None; | ||
let pairs = form_urlencoded::parse(query.as_bytes()); | ||
pairs.for_each(|(key, value)| { | ||
if key == "name" { | ||
name = Some(value.clone().into()); | ||
} | ||
if key == "surname" { | ||
surname = Some(value.clone().into()); | ||
} | ||
}); | ||
Self { | ||
name: name.unwrap(), | ||
surname: surname.unwrap(), | ||
} | ||
} | ||
} | ||
|
||
#[inline_props] | ||
fn BlogPost(cx: Scope, query_params: BlogQuerySegments) -> Element { | ||
render! { | ||
div{"This is your blogpost with a query segment:"} | ||
div{format!("{:?}", query_params)} | ||
} | ||
} | ||
|
||
fn App(cx: Scope) -> Element { | ||
render! { Router::<Route>{} } | ||
} | ||
|
||
fn main() { | ||
dioxus_web::launch(App); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,69 @@ | ||
<div align="center"> | ||
<h1>📦✨ Dioxus CLI </h1> | ||
<div style="text-align: center"> | ||
<h1>📦✨ Dioxus CLI</h1> | ||
<p><strong>Tooling to supercharge Dioxus projects</strong></p> | ||
</div> | ||
**dioxus-cli** (inspired by wasm-pack and webpack) is a tool for getting Dioxus projects up and running. | ||
It handles all build, bundling, development and publishing to simplify web development. | ||
|
||
The **dioxus-cli** (inspired by wasm-pack and webpack) is a tool for getting Dioxus projects up and running. | ||
It handles all building, bundling, development and publishing to simplify development. | ||
|
||
## Installation | ||
|
||
### Install stable version | ||
### Install the stable version (recommended) | ||
|
||
``` | ||
cargo install dioxus-cli | ||
``` | ||
### Install from git repository | ||
|
||
### Install the latest development build through git | ||
|
||
To get the latest bug fixes and features, you can install the development version from git. | ||
However, this is not fully tested. | ||
That means you're probably going to have more bugs despite having the latest bug fixes. | ||
|
||
``` | ||
cargo install --git https://github.com/DioxusLabs/dioxus dioxus-cli | ||
``` | ||
|
||
This will download the CLI from the master branch, | ||
and install it in Cargo's global binary directory (`~/.cargo/bin/` by default). | ||
|
||
### Install from local folder | ||
``` | ||
cargo install --path . --debug | ||
``` | ||
|
||
## Get started | ||
|
||
## Get Started | ||
|
||
Use `dx create project-name` to initialize a new Dioxus project. <br> | ||
|
||
Use `dx create project-name` to initialize a new Dioxus project. | ||
It will be cloned from the [dioxus-template](https://github.com/DioxusLabs/dioxus-template) repository. | ||
|
||
<br> | ||
|
||
Alternatively, you can specify the template path: | ||
|
||
``` | ||
dx create hello --template gh:dioxuslabs/dioxus-template | ||
``` | ||
|
||
## Dioxus Config File | ||
Run `dx --help` for a list of all the available commands. | ||
Furthermore, you can run `dx <command> --help` to get help with a specific command. | ||
|
||
## Dioxus config file | ||
|
||
You can use the `Dioxus.toml` file for further configuration. | ||
Some fields are mandatory, but the CLI tool will tell you which ones are missing. | ||
You can create a `Dioxus.toml` with all fields already set using `dx config init project-name`, | ||
or you can use this bare-bones template (only mandatory fields) to get started: | ||
```toml | ||
[application] | ||
name = "project-name" | ||
# Currently supported platforms: web, desktop | ||
default_platform = "web" | ||
|
||
Dioxus CLI will use `Dioxus.toml` file to Identify some project info and switch some cli feature. | ||
[web.app] | ||
title = "Hello" | ||
|
||
[web.watcher] | ||
|
||
[web.resource.dev] | ||
``` | ||
|
||
You can get more configure information from [Dioxus CLI Document](https://dioxuslabs.com/cli/configure.html). | ||
The full anatomy of `Dioxus.toml` is shown on the [Dioxus website](https://dioxuslabs.com/learn/0.4/CLI/configure). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.