modifyUrl()

The modifyUrl() function allows you to manipulate URLs.

It's usually used for extracting the locale from URLs, see Guides > Internationalization (i18n).

import { modifyUrl } from 'vike/modifyUrl'
 
const url = 'http://localhost:3000/en-US/hello/john?fruit=apple'
const urlModified = modifyUrl(url, {
  pathname: '/hello/john', // Removed en-US/
  protocol: 'https://',
  hostname: 'example.com',
  port: 3001
})
// https://example.com:3001/hello/john?fruit=apple
console.log(urlModified)

See also