Skip to content

Instantly share code, notes, and snippets.

@brillout
Last active January 24, 2024 10:39
Show Gist options
  • Save brillout/a75fd8430dbc562dd10e69007121fea0 to your computer and use it in GitHub Desktop.
Save brillout/a75fd8430dbc562dd10e69007121fea0 to your computer and use it in GitHub Desktop.
Nested Layout using a Route Function:
// /pages/product/+route.js
// This Route Function is for a Nested Layout implementation.
// It implements a route with multiple parameters.
// See:
// - https://vike.dev/route-function
// - https://vike.dev/Layout
export { route }
import { resolveRoute } from 'vike/routing'
function route(pageContext) {
{
const result = resolveRoute('/product/@id', pageContext.urlPathname)
if (result.match) {
result.routeParams.view = 'overview'
return result
}
}
{
const result = resolveRoute('/product/@id/reviews', pageContext.urlPathname)
if (result.match) {
result.routeParams.view = 'reviews'
return result
}
}
{
const result = resolveRoute('/product/@id/pricing', pageContext.urlPathname)
if (result.match) {
result.routeParams.view = 'pricing'
return result
}
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment