yewstack/yew_router
Fork: 23 Star: 90 (更新于 2024-12-16 00:24:19)
license: Apache-2.0
Language: Rust .
A routing library for the Yew frontend framework
最后发布版本: v0.11.0 ( 2020-03-14 20:04:52)
This project has been moved
This project has been incorporated into the Yew repository, and can specifically be found here. You should address all questions or improvements there instead of here. This repository will be archived in the near future.
yew-router
A routing library for the Yew frontend framework.
Example
#[derive(Switch, Debug)]
pub enum AppRoute {
#[to = "/profile/{id}"]
Profile(u32),
#[to = "/forum{*:rest}"]
Forum(ForumRoute),
#[to = "/"]
Index,
}
#[derive(Switch, Debug)]
pub enum ForumRoute {
#[to = "/{subforum}/{thread_slug}"]
SubForumAndThread{subforum: String, thread_slug: String}
#[to = "/{subforum}"]
SubForum{subforum: String}
}
html! {
<Router<AppRoute, ()>
render = Router::render(|switch: AppRoute| {
match switch {
AppRoute::Profile(id) => html!{<ProfileComponent id = id/>},
AppRoute::Index => html!{<IndexComponent/>},
AppRoute::Forum(forum_route) => html!{<ForumComponent route = forum_route/>},
}
})
/>
}
How it works
This library works by getting the url location from the browser and uses it to instantiate a type that implements Switch.
Simply using <a></a>
tags to go to your route will not work out of the box, and are inefficient because the server will return the whole app bundle again at best, and at worst just return a 404 message if the server isn't configured properly.
Using this library's RouteService, RouteAgent, RouterButton, and RouterLink to set the location via history.push_state()
will change the route without retrieving the whole app again.
Server configuration
In order for an external link to your webapp to work, the server must be configured to return the index.html
file for any GET request that would otherwise return a 404
for any conceivable client-side route.
It can't be a 3xx
redirect to index.html
, as that will change the url in the browser, causing the routing to fail - it must be a 200
response containing the content of index.html
.
Once the content of index.html
loads, it will in turn load the rest of your assets as expected and your app will start, the router will detect the current route, and set your application state accordingly.
If you choose to serve the app from the same server as your api, it is recommended to mount your api under /api
and mount your assets under /
and have /
return the content of index.html
.
Look at https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback for info on how to configure a webpack dev server to have this behavior.
How to Include
You can use the released version by adding these to your dependencies.
[dependencies]
yew-router = "0.7.0"
yew = "0.10.1"
You can use the in-development version in your project by adding it to your dependencies like so:
[dependencies]
yew-router = { git = "https://github.com/yewstack/yew_router", branch="master" }
yew = {git = "https://github.com/yewstack/yew", branch = "master"}
Minimum rustc
Currently, this library targets rustc 1.39.0, but development is done on the latest stable release. This library aims to track Yew`s minimum supported rustc version.
Contributions/Requests
If you have any questions, suggestions, or want to contribute, please open an Issue or PR and we will get back to you in a timely manner.
最近版本更新:(数据更新于 2024-10-02 17:40:58)
2020-03-14 20:04:52 v0.11.0
2020-03-03 08:09:27 v0.10.0
2020-02-25 19:55:33 v0.9.0
2020-01-10 21:18:39 v0.8.1
2020-01-10 07:35:36 v0.8.0
2019-11-12 01:31:56 v0.7.0
2019-11-02 01:25:35 v0.6.1
2019-10-25 03:46:44 v0.6.0
yewstack/yew_router同语言 Rust最近更新仓库
2024-12-22 10:23:54 rustdesk/rustdesk
2024-12-22 08:48:41 lapce/lapce
2024-12-21 23:25:36 tw93/Pake
2024-12-19 19:31:32 dashpay/platform
2024-12-18 10:31:25 DioxusLabs/dioxus
2024-12-17 17:18:34 lanyeeee/jmcomic-downloader