UNPKG

nuxt

Version:

Nuxt is a free and open-source framework with an intuitive and extendable way to create type-safe, performant and production-grade full-stack web applications and websites with Vue.js.

19 lines (18 loc) 1.03 kB
import { KeepAlive, h } from "vue"; const ROUTE_KEY_PARENTHESES_RE = /(:\w+)\([^)]+\)/g; const ROUTE_KEY_SYMBOLS_RE = /(:\w+)[?+*]/g; const ROUTE_KEY_NORMAL_RE = /:\w+/g; const interpolatePath = (route, match) => { return match.path.replace(ROUTE_KEY_PARENTHESES_RE, "$1").replace(ROUTE_KEY_SYMBOLS_RE, "$1").replace(ROUTE_KEY_NORMAL_RE, (r) => route.params[r.slice(1)]?.toString() || ""); }; export const generateRouteKey = (routeProps, override) => { const matchedRoute = routeProps.route.matched.find((m) => m.components?.default === routeProps.Component.type); const source = override ?? matchedRoute?.meta.key ?? (matchedRoute && interpolatePath(routeProps.route, matchedRoute)); return typeof source === "function" ? source(routeProps.route) : source; }; export const wrapInKeepAlive = (props, children) => { return { default: () => import.meta.client && props ? h(KeepAlive, props === true ? {} : props, children) : children }; }; export function toArray(value) { return Array.isArray(value) ? value : [value]; }