inertiajs / inertia

Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
https://inertiajs.com
MIT License
6.3k stars 423 forks source link

../ not working with Link component #1917

Open spazzymoto opened 2 months ago

spazzymoto commented 2 months ago

Version:

Describe the problem:

We are attempting to use inertia js with vue3 for our backend application but ran into some issues using the link component. We would like to be able to use relative URLs but are running into some issues using ../ to go one level in the URL back. The Link component stays on the same URL

Steps to reproduce:

If we have the following URL

http://localhost/path1/path2/path3

And on the Vue page I have the following links

<Link href="../">One level up</Link>
<a href="../">One level up</a>

The inertia link is pointing to http://localhost/path1/path2/path3 The a tag is pointing to http://localhost/path1/path2

I suspect it is cause the vue3 link component is calling mergeDataIntoQueryString which is making a new URL with 'http://localhost' as the base so it can never go one path level up from that. I suspect changing that to use window.location.toString() like hrefToUrl does would solve the issue? If you agree I am happy to open a PR with the changes?

https://github.com/inertiajs/inertia/blob/da297accbb78f9d14f766dbfdb04c517c05a7c5c/packages/core/src/url.ts#L21

Verox001 commented 2 months ago

First off I have to ask if you're using Laravel as your backend, if so that wouldn't even be supported at Laravel's end. And it would be interesting to know if the ../ in your route works, when manually inersting it into your URL.