import { redirect } from 'vike/abort'; /* eslint-disable-line import/extensions */ import { match } from 'path-to-regexp'; const path = '/user/:username/:domain?'; const urlMatch = match(path, { decode: decodeURIComponent }); export default (pageContext) => { const matched = urlMatch(pageContext.urlPathname); if (matched) { if (![undefined, 'stashes'].includes(matched.params.domain) && pageContext.user?.username !== matched.params.username) { throw redirect(`/user/${matched.params.username}`); } return { routeParams: { username: matched.params.username, domain: matched.params.domain || 'stashes', }, }; } return false; };