fix: when in browser, resolve relative links relative to current origin (closes #2806) (#2846)

This commit is contained in:
Greg Johnston 2024-08-16 20:18:59 -04:00 committed by GitHub
parent 5ed2cc9596
commit cfe2341dec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -87,6 +87,11 @@ impl LocationProvider for BrowserUrl {
})
}
fn parse(url: &str) -> Result<Url, Self::Error> {
let base = window().location().origin()?;
Self::parse_with_base(url, &base)
}
fn parse_with_base(url: &str, base: &str) -> Result<Url, Self::Error> {
let location = web_sys::Url::new_with_base(url, base)?;
Ok(Url {
@ -115,6 +120,7 @@ impl LocationProvider for BrowserUrl {
curr.origin() == new_url.origin()
&& curr.path() == new_url.path()
};
url.set(new_url);
if same_path {
Self::complete_navigation(&loc);