leptos-rs / leptos

Build fast web applications with Rust.
https://leptos.dev
MIT License
15.29k stars 599 forks source link

Support hashstyle routing #2184

Open ensc opened 5 months ago

ensc commented 5 months ago

Is your feature request related to a problem? Please describe.

atm, laptos_router works only with the url path. E.g. when http://localhost/app/ serves

    view! {
        <Router>
        <a href="home">Home</a>
        <Routes>
        <Route path="home" view=|| { view! { Home } }/>
        </Routes>
        </Router>
    }

a click on "Home" will go to http://localhost/app/home.

This creates problems with passive hosting (e.g. as gitlab/github pages) because the url does not exist and you will get an 404 error when trying to open it directly.

You have to modify server configuration to make it work (RewriteEngine on). Even in this case, it complicates accessing relative resources because document.baseURI has changed and you will have to hardcode the application uri. It pollutes also the namespace and hides invalid URLs.

Describe the solution you'd like

It would be nice when routing is implemented as html anchors. E.g. the example above would go to http://localhost/app/#home

Implementing it manually as

    view! {
        <Router>
        <a href="#home">Home</a>
        <Routes>
        <Route path="#home" view=|| { view! { Home } }/>
        </Routes>
        </Router>
    }

does not work (laptos-router 0.5.4).

Additional context

see e.g. https://router.vuejs.org/guide/essentials/history-mode.html

gbj commented 5 months ago

Sounds good! Would you like to work on a PR?

zoomiti commented 4 months ago

I can work on this.

nag763 commented 1 month ago

Hello ! Any update on this topic ? It would be helpful when the site is hosted on GH Pages for example! Thanks !