【发布时间】:2023-01-30 01:13:16
【问题描述】:
我刚刚开始使用 Rust 和 Yew 创建一个投资组合网站。我不打算做任何服务器端逻辑,所以我自然而然地认为 Github Pages 符合我的需要。
这是我在 Yew 网站上的代码。
#[derive(Debug, Clone, Copy, PartialEq, Routable)]
enum AppRoute {
#[at("/")]
Home,
#[at("/about")]
About,
#[not_found]
#[at("/404")]
NotFound,
}
#[function_component]
fn App() -> Html {
html! {
<>
<BrowserRouter>
<Switch<AppRoute> render={
|route| match route {
AppRoute::Home => html! { <h1>{ "Hello, world!" }</h1> },
AppRoute::About => html! {
<>
<h1>{ "About" }</h1>
<p> { "This page was created using " }
<a href="https://www.rust-lang.org/">{ "Rust" }</a> {", "}
<a href="https://yew.rs/">{ "Yew" }</a> {" and "}
<a href="https://trunkrs.dev/">{ "Trunk" }</a>
{ "." }
</p>
</>
},
AppRoute::NotFound => html! { <h1>{ "404: Page not found." }</h1> },
}
} />
</BrowserRouter>
</>
}
}
fn main() {
yew::Renderer::<App>::new().render();
}
我正在使用 yew-router crate 来路由到不同的页面。例如,将 url 更改为 website.github.io/about 会将我路由到 about 页面,该页面在 AppRoute 枚举中定义。
但是,当我尝试在浏览器 URL 中键入此内容时,我得到一个 Github 404 页面未找到。我认为这是因为 Github 试图找到一个名为 about 的存储库,但找不到。
我怎样才能在 URL 中使用多个页面?
【问题讨论】:
标签: rust web-deployment github-pages yew