Skip to content

Commit

Permalink
docs: document new pageContext.urlParsed props
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Jul 19, 2024
1 parent a04ec6a commit d4c1437
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
25 changes: 18 additions & 7 deletions docs/pages/pageContext/+Page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,44 @@ Built-in properties:
On the client-side:
- When using <Link href="/client-routing">Client Routing</Link>, the value of `pageContext.urlOriginal` is the browser's current URL (`window.location.href`).
- When using <Link href="/server-routing">Server Routing</Link>, the value of `pageContext.urlOriginal` is `undefined` (unless you use [`passToClient`](/passToClient)).
- **`pageContext.urlPathname`**: alias of `pageContext.urlParsed.pathname`.
- **`pageContext.urlPathname`**: alias for `pageContext.urlParsed.pathname`.
- **`pageContext.urlParsed`**: URL information:
```ts
{
origin: null | string
pathname: string
pathnameOriginal: string
search: Record<string, string> // (AKA query parameters)
search: Record<string, string> // AKA query parameters
searchAll: Record<string, string[]>
searchOriginal: null | string
hash: string
hashOriginal: null | string
href: string
origin: null | string
protocol: null | string
host: null | string
}
```

For example:
```
https://example.com/some-base-url/hello/s%C3%A9bastien?fruit=%C3%A2pple&fruit=orânge#%C3%A2ge
```
```js
// https://example.com/some-base-url/hello/s%C3%A9bastien?fruit=%C3%A2pple&fruit=orânge#%C3%A2ge
{
origin: 'https://example.com',
pathname: '/hello/sébastien', // Without Base URL
// Without Base URL, decodes escaped characters
pathname: '/hello/sébastien',
// With Base URL, doesn't decode escaped characters
pathnameOriginal: '/some-base-url/hello/s%C3%A9bastien',
search: { fruit: 'orânge' }, // (AKA query params)
search: { fruit: 'orânge' },
searchAll: { fruit: ['âpple', 'orânge'] },
searchOriginal: '?fruit=%C3%A2pple&fruit=orânge',
hash: 'âge',
hashOriginal: '#%C3%A2ge'
// Without Base URL, doesn't decode escaped characters
href: 'https://example.com/hello/s%C3%A9bastien?fruit=%C3%A2pple&fruit=orânge#%C3%A2ge',
origin: 'https://example.com',
protocol: 'https://',
host: 'example.com',
}
```
- **`pageContext.headers`**: The headers of the HTTP Request. As a string object (`Record<string, string>`) normalized by Vike, see <Link href="/headers"/>.
Expand Down
1 change: 0 additions & 1 deletion vike/utils/parseUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { slice } from './slice.js'
import { assert, assertUsage } from './assert.js'
import pc from '@brillout/picocolors'

// JSDocs copied from https://vike.dev/pageContext
type UrlPublic = {
/** The full URL. */
href: string
Expand Down

0 comments on commit d4c1437

Please sign in to comment.