leptos icon indicating copy to clipboard operation
leptos copied to clipboard

Support hashstyle routing

Open ensc opened this issue 1 year ago • 7 comments

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

ensc avatar Jan 13 '24 12:01 ensc

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

gbj avatar Jan 13 '24 12:01 gbj

I can work on this.

zoomiti avatar Feb 23 '24 01:02 zoomiti

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

nag763 avatar May 25 '24 21:05 nag763