inertia
inertia copied to clipboard
Inconsistencies between HTML and Inertia occur when a `<base>` tag is present.
Versions:
@inertiajs/inertiaversion: 0.11.0@inertiajs/inertia-vue3version: 0.6.0
Describe the problem:
I've built an application, using Inertia, that's designed for use by self-hosters.
In such environments, it's a common desire that applications can be used on a sub-path of an existing site (e.g http://example.com/app) instead of having their own domain/subdomain.
To handle such scenarios I've used relative links in my front-end, along with a html <base> tag to set the base for such relative links.
With this set-up normal link handling will work as expected (Such as opening links in new tabs), but any Inertia-driven logic will resolve the URL paths relative to the current window location rather than the configured base URL using the <base> HTML tag. This can break any URL-based Inertia actions, such as <Link>s or this.$inertia.visit()s when the HTML <base> href does not align with the current URL path.
Steps to reproduce:
- Include a base tag in the HTML template used, such as:
<base href="http://example.com/site/"> - Create an Inertia link with a non-root relative href:
<Link href="hello">Test link</Link>. - Observe different URL resolution between browser and Inertia.
Potential workarounds:
Right now I'm monkey-patching the native URL() object constructor to identity Inertia's default handling and instead patch in usage of the current page <base> href value as the base URL. This can be seen here:
https://github.com/ssddanbrown/rss/blob/5e500edcf5d1e62eb520b0201f94e003b3fe51de/resources/js/app.js#L5-L15
I could not think of other workarounds for this. I did initially seek some kind of baseURL option for inertia but could not find anything.
Additional notes
Thank you for this great package/system. I've been a long term user of Laravel and Vue, but only just trying out Inertia and I'm really impressed with the experience, it solves many time consuming pain-points, great work!
I respect this could be also considered a feature request of "Adding support for the HTML <base> tag" so would understand if you'd categorise this as such and therefore close it off. Thought it would be worthwhile to detail this out either way, for future issue searchers.
I'd be happy to work on a PR myself for this, but would first await confirmation if this is something deemed worth implementing and, if so, what kind of implementation you'd prefer (Auto-detection of base tag vs some kind of baseURL config option)