【问题标题】:Is it possible to create a multi-paged website using Github Pages and Yew?是否可以使用 Github Pages 和 Yew 创建多页面网站?
【发布时间】: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


    【解决方案1】:

    根据以下 Stack Overflow 回答,我的理论是您需要使用 HashRouter

    警告:我是 Yew 的新手,没有使用 GitHub Pages 的经验。我刚遇到这个 最近在研究 Yew 路由时。以下是我发现的一些更特定于 Rust/Yew 的其他内容:

    希望这可以帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-30
      • 2020-03-22
      • 2017-04-08
      • 1970-01-01
      • 2023-03-17
      • 2015-03-12
      相关资源
      最近更新 更多