-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
Relative base such as ./
#606
Comments
This comment was marked as outdated.
This comment was marked as outdated.
ProblemWhen pre-rendering, because the HTML is set in stone, static assets need to be referenced with relative paths (e.g. <!-- URL (logical): / -->
<!-- URL (real, example 1): /some-base/ -->
<!-- URL (real, example 2): /some/nested/base/ -->
<img src="./assets/logo.aeuh81a.svg" />
<a href="./about-us" /> <!-- URL (logical): /product/edit/42 -->
<!-- URL (real, example 1): /some-base/product/edit/42 -->
<!-- URL (real, example 2): /some/nested/base/product/edit/42 -->
<img src="../../assets/logo.aeuh81a.svg" />
<a href="../../about-us" /> Solutionimport { makeUrlRelative } from 'vike'
import { usePageContext } from 'vike-{react,vue,solid}'
import logoUrl from './logo.svg'
function SomeComponent() {
const pageContext = usePageContext()
return <>
<a href={makeUrlRelative('/product/42', pageContext)} />
<img src={makeUrlRelative(logoUrl, pageContext)} />
</>
} Contribute
Remarks
|
This comment was marked as outdated.
This comment was marked as outdated.
Fun timing on this one, I just came across this limitation when trying to use Vike for a project. The lack of support here is a little bit of a blocker for my use case in which the app is served by Vite/Vike via SSG and exposed indirectly via a proxy attached to arbitrary base paths-- in particular, there is no one specific fixed path, and it is chosen entirely by the proxy, not the application sitting behind it. Think about it like this (it's not exactly this, but this use case would fail in the same way): I'm generating a self contained application that is vended out to third parties all over the Internet and will be hosted in a white label fashion on various external properties at various locations. The static generation is an important piece to this limitation, as this works fine via SSR (since we can hijack routing) but breaks when generating static files. Unfortunately, static pre-render generation was the entire purpose for using Vike in the first place. A lot is being mentioned about "assets", and I'm not entirely sure if Vike classifies its own chunks/compiled assets as "assets" in the same sense, but in my case, the big issue that breaks are the
I'm a little confused about the "possible" statement, as surely it is explicitly "possible" to generate relative links between documents (certainly this is a well known and very-solved problem). Is there some Vite API getting in the way? If so, that seems odd, since Vite itself supports a relative base. Are there any workarounds for this use case, or is Vike not going to work for this use case? |
I agree your use case makes sense. What isn't clear is whether it's feasible to achieve that without ending up with a frankenstein (e.g. relative links are fundamentally broken in multi-page React/Vue/... apps). Is there any React/Vue/... SSR framework out there that supports relative base paths? I honestly doubt it, but I'm happy to be shown wrong. Also sponsoring welcome (you'll get a bump in priority). |
Couldn't this be handled within a The logic doesn't seem too wild to me: Prepend links with I could have sworn this existed in Nuxt once but it's broken there rn. Relevant for static deployments to e.g. IPFS, since you don't know the path the deployment ends up in before building. |
This comment was marked as outdated.
This comment was marked as outdated.
Another use case: #1223 (comment). |
Re-opening as there seem to be a solution for this. |
./admin/
instead of /admin/
)./
We are currently experiencing challenges regarding this issue. Our use case involves deploying our React application in two distinct environments, each with unique requirements:
We really need support for a relative base path in Vike, or a feasible workaround (possibly without pre-rendering?) for the second mentioned environment. So this issue is a critical deal-breaker for us. If we can ensure that the necessary support will be available before June, I am willing to provide financial support for the project as well, as Vike is an otherwise perfect fit for our needs. 🙌 |
I see.
While I beileve the aforementioned solution will work, there are quite a lot of higher priority things in the pipeline, especially given that I foresee the implementation to be far from trivial. So I'm not sure how much sponsoring would help, but it depends on how much you'd be willing to sponsor. Feel free to PM us. Also, what would help is doing some research wehther other frameworks support that. It would help us a lot to see a real world solution to this. |
I see why this is a problem for MPAs and SSR environments. But I wonder if it would be possible to make relative base paths work in an SPA. For our use case we only need relative base path support for one customer specific deployment where we don't need to support pre-rendering, SSR nor being crawlable in the first place. Therefore, switching the entire Vike app to SPA "mode" + client side routing should technically allow us to add a relative base path, right? |
@CookedApps I'm reluctant to work on a solution that would work for only a small minority of users, even if it means less work. |
@brillout I understand and respect your stance on not focusing on features for a minority of users. I'm not expecting you to invest time in our specific issue, but I would appreciate any guidance or suggestions for possible workarounds. I'm also open to contributing to Vike directly and enrich the framework by adding such functionality. A bit of initial direction from the maintainers would be really helpful, as I'm currently finding it challenging to get involved, despite my enthusiasm for the project. Thanks for considering this! |
Description
Vite supports setting
base
to./
for "embedded deployments", see vite.config.js#base. Can Vike support such relative base paths?The text was updated successfully, but these errors were encountered: