diff --git a/vike/shared/getPageContextUrlComputed.ts b/vike/shared/getPageContextUrlComputed.ts index 89218bcf093..42fe43eebf8 100644 --- a/vike/shared/getPageContextUrlComputed.ts +++ b/vike/shared/getPageContextUrlComputed.ts @@ -25,6 +25,10 @@ import { // JSDocs copied from https://vike.dev/pageContext type Url = { + /** The full URL. (Without Base URL.) */ + href: null | string + /** The full URL. (With Base URL.) */ + hrefOriginal: null | string /** The URL protocol, e.g. `https://` in `https://example.com` */ protocol: null | string /** The URL origin, e.g. `https://example.com` in `https://example.com/product/42?details=yes#reviews` */ diff --git a/vike/utils/parseUrl.ts b/vike/utils/parseUrl.ts index 2760254579d..d2ebeaa49cb 100644 --- a/vike/utils/parseUrl.ts +++ b/vike/utils/parseUrl.ts @@ -24,6 +24,8 @@ function parseUrl( url: string, baseServer: string ): { + href: string + hrefOriginal: string protocol: null | string origin: null | string pathname: string @@ -76,8 +78,13 @@ function parseUrl( let { pathname, hasBaseServer } = analyzeBaseServer(pathnameResolved, baseServer) pathname = decodePathname(pathname) + const href = createUrlFromComponents(origin, pathname, searchOriginal, hashOriginal) + const hrefOriginal = createUrlFromComponents(origin, pathnameOriginal, searchOriginal, hashOriginal) + assert(pathname.startsWith('/')) return { + href, + hrefOriginal, protocol, origin, pathname,