Skip to content

Commit

Permalink
feat: pageContext.urlParsed.href (closes vikejs#1630)
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Jul 19, 2024
1 parent 2eaeea4 commit d802189
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vike/shared/getPageContextUrlComputed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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` */
Expand Down
7 changes: 7 additions & 0 deletions vike/utils/parseUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function parseUrl(
url: string,
baseServer: string
): {
href: string
hrefOriginal: string
protocol: null | string
origin: null | string
pathname: string
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d802189

Please sign in to comment.