feat: init
This commit is contained in:
2
node_modules/nuxt/dist/pages/runtime/plugins/check-if-page-unused.d.ts
generated
vendored
Normal file
2
node_modules/nuxt/dist/pages/runtime/plugins/check-if-page-unused.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare const _default: any;
|
||||
export default _default;
|
||||
29
node_modules/nuxt/dist/pages/runtime/plugins/check-if-page-unused.js
generated
vendored
Normal file
29
node_modules/nuxt/dist/pages/runtime/plugins/check-if-page-unused.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { nextTick } from "vue";
|
||||
import { defineNuxtPlugin } from "#app/nuxt";
|
||||
import { onNuxtReady } from "#app/composables/ready";
|
||||
import { useError } from "#app/composables/error";
|
||||
export default defineNuxtPlugin({
|
||||
name: "nuxt:checkIfPageUnused",
|
||||
setup(nuxtApp) {
|
||||
const error = useError();
|
||||
function checkIfPageUnused() {
|
||||
if (!error.value && !nuxtApp._isNuxtPageUsed) {
|
||||
console.warn(
|
||||
"[nuxt] Your project has pages but the `<NuxtPage />` component has not been used. You might be using the `<RouterView />` component instead, which will not work correctly in Nuxt. You can set `pages: false` in `nuxt.config` if you do not wish to use the Nuxt `vue-router` integration."
|
||||
);
|
||||
}
|
||||
}
|
||||
if (import.meta.server) {
|
||||
nuxtApp.hook("app:rendered", ({ renderResult }) => {
|
||||
if (renderResult?.html) {
|
||||
nextTick(checkIfPageUnused);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
onNuxtReady(checkIfPageUnused);
|
||||
}
|
||||
},
|
||||
env: {
|
||||
islands: false
|
||||
}
|
||||
});
|
||||
2
node_modules/nuxt/dist/pages/runtime/plugins/prefetch.client.d.ts
generated
vendored
Normal file
2
node_modules/nuxt/dist/pages/runtime/plugins/prefetch.client.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare const _default: any;
|
||||
export default _default;
|
||||
41
node_modules/nuxt/dist/pages/runtime/plugins/prefetch.client.js
generated
vendored
Normal file
41
node_modules/nuxt/dist/pages/runtime/plugins/prefetch.client.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { hasProtocol } from "ufo";
|
||||
import { toArray } from "../utils.js";
|
||||
import { defineNuxtPlugin } from "#app/nuxt";
|
||||
import { useRouter } from "#app/composables/router";
|
||||
import layouts from "#build/layouts";
|
||||
import { namedMiddleware } from "#build/middleware";
|
||||
import { _loadAsyncComponent } from "#app/composables/preload";
|
||||
export default defineNuxtPlugin({
|
||||
name: "nuxt:prefetch",
|
||||
setup(nuxtApp) {
|
||||
const router = useRouter();
|
||||
nuxtApp.hooks.hook("app:mounted", () => {
|
||||
router.beforeEach(async (to) => {
|
||||
const layout = to?.meta?.layout;
|
||||
if (layout && typeof layouts[layout] === "function") {
|
||||
await layouts[layout]();
|
||||
}
|
||||
});
|
||||
});
|
||||
nuxtApp.hooks.hook("link:prefetch", (url) => {
|
||||
if (hasProtocol(url)) {
|
||||
return;
|
||||
}
|
||||
const route = router.resolve(url);
|
||||
if (!route) {
|
||||
return;
|
||||
}
|
||||
const layout = route.meta.layout;
|
||||
let middleware = toArray(route.meta.middleware);
|
||||
middleware = middleware.filter((m) => typeof m === "string");
|
||||
for (const name of middleware) {
|
||||
if (typeof namedMiddleware[name] === "function") {
|
||||
namedMiddleware[name]();
|
||||
}
|
||||
}
|
||||
if (typeof layout === "string" && layout in layouts) {
|
||||
_loadAsyncComponent(layouts[layout]);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
2
node_modules/nuxt/dist/pages/runtime/plugins/prerender.server.d.ts
generated
vendored
Normal file
2
node_modules/nuxt/dist/pages/runtime/plugins/prerender.server.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare const _default: any;
|
||||
export default _default;
|
||||
42
node_modules/nuxt/dist/pages/runtime/plugins/prerender.server.js
generated
vendored
Normal file
42
node_modules/nuxt/dist/pages/runtime/plugins/prerender.server.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import { joinURL } from "ufo";
|
||||
import { defineNuxtPlugin } from "#app/nuxt";
|
||||
import { prerenderRoutes } from "#app/composables/ssr";
|
||||
import _routes from "#build/routes";
|
||||
import routerOptions, { hashMode } from "#build/router.options.mjs";
|
||||
import { crawlLinks } from "#build/nuxt.config.mjs";
|
||||
import _routeRulesMatcher from "#build/route-rules.mjs";
|
||||
const routeRulesMatcher = _routeRulesMatcher;
|
||||
let routes;
|
||||
export default defineNuxtPlugin(async () => {
|
||||
if (!import.meta.server || !import.meta.prerender || hashMode) {
|
||||
return;
|
||||
}
|
||||
if (routes && !routes.length) {
|
||||
return;
|
||||
}
|
||||
routes ||= Array.from(processRoutes(await routerOptions.routes?.(_routes) ?? _routes));
|
||||
const batch = routes.splice(0, 10);
|
||||
prerenderRoutes(batch);
|
||||
});
|
||||
const OPTIONAL_PARAM_RE = /^\/?:.*(?:\?|\(\.\*\)\*)$/;
|
||||
function shouldPrerender(path) {
|
||||
return crawlLinks || !!routeRulesMatcher(path).prerender;
|
||||
}
|
||||
function processRoutes(routes2, currentPath = "/", routesToPrerender = /* @__PURE__ */ new Set()) {
|
||||
for (const route of routes2) {
|
||||
if (OPTIONAL_PARAM_RE.test(route.path) && !route.children?.length && shouldPrerender(currentPath)) {
|
||||
routesToPrerender.add(currentPath);
|
||||
}
|
||||
if (route.path.includes(":")) {
|
||||
continue;
|
||||
}
|
||||
const fullPath = joinURL(currentPath, route.path);
|
||||
if (shouldPrerender(fullPath)) {
|
||||
routesToPrerender.add(fullPath);
|
||||
}
|
||||
if (route.children) {
|
||||
processRoutes(route.children, fullPath, routesToPrerender);
|
||||
}
|
||||
}
|
||||
return routesToPrerender;
|
||||
}
|
||||
6
node_modules/nuxt/dist/pages/runtime/plugins/router.d.ts
generated
vendored
Normal file
6
node_modules/nuxt/dist/pages/runtime/plugins/router.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import type { Router } from 'vue-router';
|
||||
import type { Plugin } from 'nuxt/app';
|
||||
declare const plugin: Plugin<{
|
||||
router: Router;
|
||||
}>;
|
||||
export default plugin;
|
||||
233
node_modules/nuxt/dist/pages/runtime/plugins/router.js
generated
vendored
Normal file
233
node_modules/nuxt/dist/pages/runtime/plugins/router.js
generated
vendored
Normal file
@@ -0,0 +1,233 @@
|
||||
import { isReadonly, reactive, shallowReactive, shallowRef } from "vue";
|
||||
import { START_LOCATION, createMemoryHistory, createRouter, createWebHashHistory, createWebHistory } from "vue-router";
|
||||
import { isSamePath, withoutBase } from "ufo";
|
||||
import { toArray } from "../utils.js";
|
||||
import { getRouteRules } from "#app/composables/manifest";
|
||||
import { defineNuxtPlugin, useRuntimeConfig } from "#app/nuxt";
|
||||
import { clearError, createError, isNuxtError, showError, useError } from "#app/composables/error";
|
||||
import { navigateTo } from "#app/composables/router";
|
||||
import _routes, { handleHotUpdate } from "#build/routes";
|
||||
import routerOptions, { hashMode } from "#build/router.options.mjs";
|
||||
import { globalMiddleware, namedMiddleware } from "#build/middleware";
|
||||
function createCurrentLocation(base, location, renderedPath) {
|
||||
const { pathname, search, hash } = location;
|
||||
const hashPos = base.indexOf("#");
|
||||
if (hashPos > -1) {
|
||||
const slicePos = hash.includes(base.slice(hashPos)) ? base.slice(hashPos).length : 1;
|
||||
let pathFromHash = hash.slice(slicePos);
|
||||
if (pathFromHash[0] !== "/") {
|
||||
pathFromHash = "/" + pathFromHash;
|
||||
}
|
||||
return withoutBase(pathFromHash, "");
|
||||
}
|
||||
const displayedPath = withoutBase(pathname, base);
|
||||
const path = !renderedPath || isSamePath(displayedPath, renderedPath) ? displayedPath : renderedPath;
|
||||
return path + (path.includes("?") ? "" : search) + hash;
|
||||
}
|
||||
const plugin = defineNuxtPlugin({
|
||||
name: "nuxt:router",
|
||||
enforce: "pre",
|
||||
async setup(nuxtApp) {
|
||||
let routerBase = useRuntimeConfig().app.baseURL;
|
||||
if (hashMode && !routerBase.includes("#")) {
|
||||
routerBase += "#";
|
||||
}
|
||||
const history = routerOptions.history?.(routerBase) ?? (import.meta.client ? hashMode ? createWebHashHistory(routerBase) : createWebHistory(routerBase) : createMemoryHistory(routerBase));
|
||||
const routes = routerOptions.routes ? await routerOptions.routes(_routes) ?? _routes : _routes;
|
||||
let startPosition;
|
||||
const router = createRouter({
|
||||
...routerOptions,
|
||||
scrollBehavior: (to, from, savedPosition) => {
|
||||
if (from === START_LOCATION) {
|
||||
startPosition = savedPosition;
|
||||
return;
|
||||
}
|
||||
if (routerOptions.scrollBehavior) {
|
||||
router.options.scrollBehavior = routerOptions.scrollBehavior;
|
||||
if ("scrollRestoration" in window.history) {
|
||||
const unsub = router.beforeEach(() => {
|
||||
unsub();
|
||||
window.history.scrollRestoration = "manual";
|
||||
});
|
||||
}
|
||||
return routerOptions.scrollBehavior(to, START_LOCATION, startPosition || savedPosition);
|
||||
}
|
||||
},
|
||||
history,
|
||||
routes
|
||||
});
|
||||
if (import.meta.hot) {
|
||||
handleHotUpdate(router, routerOptions.routes ? routerOptions.routes : (routes2) => routes2);
|
||||
}
|
||||
if (import.meta.client && "scrollRestoration" in window.history) {
|
||||
window.history.scrollRestoration = "auto";
|
||||
}
|
||||
nuxtApp.vueApp.use(router);
|
||||
const previousRoute = shallowRef(router.currentRoute.value);
|
||||
router.afterEach((_to, from) => {
|
||||
previousRoute.value = from;
|
||||
});
|
||||
Object.defineProperty(nuxtApp.vueApp.config.globalProperties, "previousRoute", {
|
||||
get: () => previousRoute.value
|
||||
});
|
||||
const initialURL = import.meta.server ? nuxtApp.ssrContext.url : createCurrentLocation(routerBase, window.location, nuxtApp.payload.path);
|
||||
const _route = shallowRef(router.currentRoute.value);
|
||||
const syncCurrentRoute = () => {
|
||||
_route.value = router.currentRoute.value;
|
||||
};
|
||||
router.afterEach((to, from) => {
|
||||
if (to.matched.at(-1)?.components?.default === from.matched.at(-1)?.components?.default) {
|
||||
syncCurrentRoute();
|
||||
}
|
||||
});
|
||||
const route = { sync: syncCurrentRoute };
|
||||
for (const key in _route.value) {
|
||||
Object.defineProperty(route, key, {
|
||||
get: () => _route.value[key],
|
||||
enumerable: true
|
||||
});
|
||||
}
|
||||
nuxtApp._route = shallowReactive(route);
|
||||
nuxtApp._middleware ||= {
|
||||
global: [],
|
||||
named: {}
|
||||
};
|
||||
const error = useError();
|
||||
if (import.meta.client || !nuxtApp.ssrContext?.islandContext) {
|
||||
router.afterEach(async (to, _from, failure) => {
|
||||
delete nuxtApp._processingMiddleware;
|
||||
if (import.meta.client && !nuxtApp.isHydrating && error.value) {
|
||||
await nuxtApp.runWithContext(clearError);
|
||||
}
|
||||
if (failure) {
|
||||
await nuxtApp.callHook("page:loading:end");
|
||||
}
|
||||
if (import.meta.server && failure?.type === 4) {
|
||||
return;
|
||||
}
|
||||
if (import.meta.server && to.redirectedFrom && to.fullPath !== initialURL) {
|
||||
await nuxtApp.runWithContext(() => navigateTo(to.fullPath || "/"));
|
||||
}
|
||||
});
|
||||
}
|
||||
try {
|
||||
if (import.meta.server) {
|
||||
await router.push(initialURL);
|
||||
}
|
||||
await router.isReady();
|
||||
} catch (error2) {
|
||||
await nuxtApp.runWithContext(() => showError(error2));
|
||||
}
|
||||
const resolvedInitialRoute = import.meta.client && initialURL !== router.currentRoute.value.fullPath ? router.resolve(initialURL) : router.currentRoute.value;
|
||||
syncCurrentRoute();
|
||||
if (import.meta.server && nuxtApp.ssrContext?.islandContext) {
|
||||
return { provide: { router } };
|
||||
}
|
||||
const initialLayout = nuxtApp.payload.state._layout;
|
||||
router.beforeEach(async (to, from) => {
|
||||
await nuxtApp.callHook("page:loading:start");
|
||||
to.meta = reactive(to.meta);
|
||||
if (nuxtApp.isHydrating && initialLayout && !isReadonly(to.meta.layout)) {
|
||||
to.meta.layout = initialLayout;
|
||||
}
|
||||
nuxtApp._processingMiddleware = true;
|
||||
if (import.meta.client || !nuxtApp.ssrContext?.islandContext) {
|
||||
const middlewareEntries = /* @__PURE__ */ new Set([...globalMiddleware, ...nuxtApp._middleware.global]);
|
||||
for (const component of to.matched) {
|
||||
const componentMiddleware = component.meta.middleware;
|
||||
if (!componentMiddleware) {
|
||||
continue;
|
||||
}
|
||||
for (const entry of toArray(componentMiddleware)) {
|
||||
middlewareEntries.add(entry);
|
||||
}
|
||||
}
|
||||
const routeRules = getRouteRules({ path: to.path });
|
||||
if (routeRules.appMiddleware) {
|
||||
for (const key in routeRules.appMiddleware) {
|
||||
if (routeRules.appMiddleware[key]) {
|
||||
middlewareEntries.add(key);
|
||||
} else {
|
||||
middlewareEntries.delete(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const entry of middlewareEntries) {
|
||||
const middleware = typeof entry === "string" ? nuxtApp._middleware.named[entry] || await namedMiddleware[entry]?.().then((r) => r.default || r) : entry;
|
||||
if (!middleware) {
|
||||
if (import.meta.dev) {
|
||||
throw new Error(`Unknown route middleware: '${entry}'. Valid middleware: ${Object.keys(namedMiddleware).map((mw) => `'${mw}'`).join(", ")}.`);
|
||||
}
|
||||
throw new Error(`Unknown route middleware: '${entry}'.`);
|
||||
}
|
||||
try {
|
||||
if (import.meta.dev) {
|
||||
nuxtApp._processingMiddleware = middleware._path || (typeof entry === "string" ? entry : true);
|
||||
}
|
||||
const result = await nuxtApp.runWithContext(() => middleware(to, from));
|
||||
if (import.meta.server || !nuxtApp.payload.serverRendered && nuxtApp.isHydrating) {
|
||||
if (result === false || result instanceof Error) {
|
||||
const error2 = result || createError({
|
||||
status: 404,
|
||||
statusText: `Page Not Found: ${initialURL}`
|
||||
});
|
||||
await nuxtApp.runWithContext(() => showError(error2));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (result === true) {
|
||||
continue;
|
||||
}
|
||||
if (result === false) {
|
||||
return result;
|
||||
}
|
||||
if (result) {
|
||||
if (isNuxtError(result) && result.fatal) {
|
||||
await nuxtApp.runWithContext(() => showError(result));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} catch (err) {
|
||||
const error2 = createError(err);
|
||||
if (error2.fatal) {
|
||||
await nuxtApp.runWithContext(() => showError(error2));
|
||||
}
|
||||
return error2;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
router.onError(async () => {
|
||||
delete nuxtApp._processingMiddleware;
|
||||
await nuxtApp.callHook("page:loading:end");
|
||||
});
|
||||
router.afterEach((to) => {
|
||||
if (to.matched.length === 0 && !error.value) {
|
||||
return nuxtApp.runWithContext(() => showError(createError({
|
||||
status: 404,
|
||||
fatal: false,
|
||||
statusText: `Page not found: ${to.fullPath}`,
|
||||
data: {
|
||||
path: to.fullPath
|
||||
}
|
||||
})));
|
||||
}
|
||||
});
|
||||
nuxtApp.hooks.hookOnce("app:created", async () => {
|
||||
try {
|
||||
if ("name" in resolvedInitialRoute) {
|
||||
resolvedInitialRoute.name = void 0;
|
||||
}
|
||||
await router.replace({
|
||||
...resolvedInitialRoute,
|
||||
force: true
|
||||
});
|
||||
router.options.scrollBehavior = routerOptions.scrollBehavior;
|
||||
} catch (error2) {
|
||||
await nuxtApp.runWithContext(() => showError(error2));
|
||||
}
|
||||
});
|
||||
return { provide: { router } };
|
||||
}
|
||||
});
|
||||
export default plugin;
|
||||
Reference in New Issue
Block a user