nuxt
Version:
[](https://nuxt.com)
13 lines (12 loc) • 785 B
JavaScript
import { KeepAlive, h } from "vue";
const interpolatePath = (route, match) => {
return match.path.replace(/(:\w+)\([^)]+\)/g, "$1").replace(/(:\w+)[?+*]/g, "$1").replace(/:\w+/g, (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: () => process.client && props ? h(KeepAlive, props === true ? {} : props, children) : children };
};