DioxusLabs / dioxus

Fullstack GUI library for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
19.37k stars 747 forks source link

Routing errors and the use of Manganis if the site is located in a subdirectory of the domain, as on GitHub Pages. #2093

Open DioxusGrow opened 3 months ago

DioxusGrow commented 3 months ago

Problem

At the moment, routing faces significant issues when the site is located in a subdirectory, as on GitHub Pages. For example, consider the site at https://dioxusgrow.github.io/crabsburger/.

Steps To Reproduce

Steps to reproduce the behavior:

Cargo.toml

[dependencies]
chrono = "0.4.31"
dioxus = { git = "https://github.com/DioxusLabs/dioxus", features = ["web", "router"] }
manganis = "0.2.1"
wasm-bindgen = "0.2.89"

The Dioxus.toml file needs to specify the following settings:

[web.app]
base_path = "crabsburger"
# uncomment the line below if using Router
index_on_404 = true
# include `assets` in the web platform
[web.resource]
# CSS style file
style = ["/crabsburger/tailwind.css"]

The Route is used with the following settings:

#[derive(Routable, Clone, Debug, PartialEq)]
#[rustfmt::skip]
pub enum Route {        
    #[layout(NavBar)]        
        #[route("/")]
        Home {},
    #[end_layout]
    #[route("/:..route")]
    PageNotFound {
        route: Vec<String>,
    },
}

When navigating to https://dioxusgrow.github.io/crabsburger/, it will redirect to https://dioxusgrow.github.io/. To ensure the CSS files work correctly, you must specify in the Dioxus.toml file:

[web.resource]
# CSS style file
style = ["/crabsburger/tailwind.css"]

Additionally, each image must include the subfolder name of the site for proper display, like so:

src: "crabsburger/images/home-image.png",

Expected behavior

However, if you reload the main domain https://dioxusgrow.github.io/, the route will no longer work, resulting in a 404 error from GitHub itself. Manganis cannot handle subdirectories at all, making it impossible to use if the site is located in a subdirectory of the main domain.

Therefore, if test sites are located in GitHub’s subdirectories, you should either create single-page applications without routing or use other platforms, such as Netlify, which uses subdomains for test deployments, or connect existing root domain addresses.

Screenshots

If applicable, add screenshots to help explain your problem.

Environment:

AceofSpades5757 commented 3 months ago

I've had no end to issues trying to set a base path. Nothing works the way I would expect it to (web and fullstack) and workarounds have been giving strange errors. I'm going to create a post in Discord to try and get some assistance as well.

For reference, I've been using the most up-to-date tools for Dioxus and tools at 0.5.1 and rustc 1.77.1 on Windows 10 and my Ubuntu 20.04.6 LTS web server.