vikejs / vike

🔨 Flexible, lean, community-driven, dependable, fast Vite-based frontend framework.
https://vike.dev
MIT License
3.87k stars 334 forks source link

Offer `href` in `urlParsed` #1630

Open openscript opened 2 months ago

openscript commented 2 months ago

Description

In my opinion urlParsed should contain a href. My reasoning is URL also contains that and the DX would improve.

For example https://vike.dev/i18n describes:

const urlWithoutLocale = `${origin || ''}${pathnameWithoutLocale}${searchOriginal || ''}${hashOriginal || ''}`

This would become

const urlWithoutLocale = url.href.replace(url.pathname, url.pathnameWithoutLocale)
brillout commented 2 months ago

Agreed :+1: Would you be up for PR for this as well? AFAICT this one should actually be fairly easy (easier than the other one).

(On a tangent, I was thinking it would also be nice to offer/document an easier way to manipulate the URL. The issue with url.href.replace(url.pathname, url.pathnameWithoutLocale) is that it may fail for example for a url.pathname that is /en and a URL /en?movies/endeavour which would become /?movies/deavour.)

openscript commented 2 months ago

Would you be up for PR for this as well?

Sure, I'll give it a try. :)