-
-
Notifications
You must be signed in to change notification settings - Fork 833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base_path needed for deploy, but breaks local serve #2285
Comments
I had some success using the latest CLI instead (thanks to #2381): cargo install --git https://github.com/DioxusLabs/dioxus.git dioxus-cli With that, fetching This wasn't all the way there in my case as assets weren't loading properly. Naturally, as there was no trailing So I tried adding a trailing It's available here: https://github.com/s1gtrap/dioxus/tree/fix-relative-assets-w-base-path but I'll create a PR in a sec. |
@s1gtrap I can share some details from my digging for #2381 and #2395
From what I can see, this isn't intended but I don't think the Dioxus team has any (direct) say in the matter. From what I can tell from some issues open in tokio-rs/axum, there's a surprising (TBD if that means "bug," I guess?) interaction between I've put together a little demo axum server to demonstrate this. I'll push it to GH and edit this comment w/ a link in a few. Your comment from #2403,
This really surprised me, as it's not the behavior I've observed in my puttering. May I ask what OS you're running this on? I'd love to see a minimal reproduction of that behavior.
My understanding is that there's no real way of getting around this, and that (for this style of "single"-page app) assets need to be served as absolute paths. I may well be wrong, and I'd love to be corrected as it's been a few years since I've written any real React, but consider deep links. Given a That said, I think there's room for improvement in the dx server to better handle assets in apps that include a And a final note, I do have a workaround for the Folded code b/c this comment is already long enoughThis code is offered as-is, probably buggy, MIT, YMMV, ETC. /// Extensions for the Axum [`Router`] type.
pub trait AxumRouterExt<S>
where
S: Clone + Send + Sync + 'static,
{
/// Nest a Router that is expected to include a fallback.
///
/// This function is designed to mitigate the issues (or perhaps surprises)
/// described in [tokio-rs/axum#2659] by first nesting the given `router` as
/// per [`Router::nest`], and then adding an additional route that redirects
/// `{path}/` to `{path}`.
///
/// [tokio-rs/axum#2659]: https://github.com/tokio-rs/axum/issues/2659#issuecomment-2016666385
fn nest_hosting_fallback(
self,
path: impl AsRef<str>,
router: Router<S>,
) -> Self;
}
impl<S> AxumRouterExt<S> for Router<S>
where
S: Clone + Send + Sync + 'static,
{
fn nest_hosting_fallback(
self,
path: impl AsRef<str>,
router: Router<S>,
) -> Self {
// TODO: This will break if path has a trailing slash. Should we panic
// if that happens? Let users configure nonsense routes? Make this
// fallible?
let path = path.as_ref();
let path_trailing_slash = format!("{}/", path);
self.route(
&path_trailing_slash,
get({
let path = path.to_owned();
// Capture raw query params and forward them in the redirect.
|RawQuery(params): RawQuery| async move {
let target = if let Some(params) = params {
format!("{path}?{params}")
} else {
format!("{path}")
};
Redirect::permanent(target.as_ref())
}
}),
)
.nest(path, router)
}
} |
I'm also running into the same problem, two potential work arounds:
|
I have resolved that problem using manganis crate. For instances, pub const ICON_POLL: &str = manganis::mg!(file("assets/icons/icon-poll.svg")); will serve static files successfully. |
Problem
I need to set [web.app]base_path in Dioxus.toml to get deployment on Github Pages working. But then locally the app refuses to work as it is replaced by an error message ("Outside of the base path: /your-path"). Is it possible to get both to work?
Environment:
The text was updated successfully, but these errors were encountered: