Skip to content
This repository was archived by the owner on Jul 19, 2020. It is now read-only.
This repository was archived by the owner on Jul 19, 2020. It is now read-only.

Fragment route not working #193

@jetli

Description

@jetli

Describe the Bug
Fragment route like #/login seems not working, there is a leading / in RouteService.get_route which causes mismatch, or even a leading /rust-yew-realworld-example-app/ if the website is hosted in a sub folder, e.g. https://jetli.github.io/rust-yew-realworld-example-app/

#[derive(Switch, Debug, Clone)]
pub enum AppRoute {
    #[to = "#/login"]
    Login,
    #[to = "#/"]
    Home,
}

For now, to use gh-pages to host the demo site, I have to fix the routing by:

/// Fix fragment handling for yew_router
pub fn fix_fragment_router(route: &mut Route) {
    let r = route.route.as_str();
    if let Some(index) = r.find("#") {
        route.route = r[index..].to_string();
    } else {
        route.route = "#/".to_string();
    }
}

https://github.com/jetli/rust-yew-realworld-example-app/blob/a99af18ec64ef74d6c3ac97419fc7de47eaa892d/crates/conduit-wasm/src/routes.rs#L29

https://github.com/jetli/rust-yew-realworld-example-app/blob/a99af18ec64ef74d6c3ac97419fc7de47eaa892d/crates/conduit-wasm/src/components/app.rs#L42

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions