Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

生成的路由有问题 #12

Closed
AK47HaiJun opened this issue Dec 18, 2023 · 2 comments
Closed

生成的路由有问题 #12

AK47HaiJun opened this issue Dec 18, 2023 · 2 comments
Assignees
Labels
invalid This doesn't seem right

Comments

@AK47HaiJun
Copy link

AK47HaiJun commented Dec 18, 2023

我是基于文件生成的路由,使用后,一级路由出现了 children
这是我的main.ts 配置

import { createApp } from 'vue'
import App from './App.vue'
import { createHead } from '@vueuse/head'
import 'ant-design-vue/dist/reset.css';
import Antd from 'ant-design-vue';

import { routes } from "vue-router/auto/routes"; // 引入文件路由表
import { setupLayouts } from "virtual:meta-layouts";
import { createRouter, createWebHistory } from "vue-router";

const router = createRouter({
  routes: setupLayouts(routes), // 注册文件路由表
  history: createWebHistory(),
});

// 管理页面的head 
const head = createHead()


const app = createApp(App);
app.use(router);
app.use(Antd)
app.use(head)
app.mount('#app');
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import Pages from "vite-plugin-pages";
import MetaLayouts from "vite-plugin-vue-meta-layouts";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import VueRouter from "unplugin-vue-router/vite";
import { VueRouterAutoImports } from "unplugin-vue-router";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    VueRouter({
      /* options */
    }),
    Pages({
      // 配置项(如果有)
    }),
    MetaLayouts({
      target: "src/layouts", // 布局目录,默认 src/layouts
      defaultLayout: "default", // 默认布局,默认为 default
      importMode: "sync", // 加载模式,支持 sync 和 async。默认为自动处理,SSG 时为 sync,非 SSG 时为 async
    }),
    // 配置 unplugin-auto-import
    AutoImport({
      imports: [
        "vue",
        "vue-router",
      ],
      dts: "src/auto-imports.d.ts", // 生成 .d.ts 文件,提供类型提示
    }),
    // 配置 unplugin-vue-components
    Components({
      resolvers: [],
      // 其他配置...
    }),
  ],
});

我是基于文件生成路由的,用的 vite-plugin-pages 插件
并且我也在页面中指定了 layout

<route> { meta: { layout: 'test' } } </route>

我的layouts 文件
image

image
@AK47HaiJun AK47HaiJun closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2023
@AK47HaiJun AK47HaiJun changed the title 使用了后,页面不能正常显示 生成的路由有问题 Dec 18, 2023
@AK47HaiJun AK47HaiJun reopened this Dec 18, 2023
@AK47HaiJun
Copy link
Author

.

@markthree
Copy link
Member

@AK47HaiJun 靓仔,这不是 bug 哦,为了实现布局,故意这么做的,具体可见源码 → deepSetupLayout 或者实现原理 → how-it-works

@markthree markthree self-assigned this Dec 19, 2023
@markthree markthree added the invalid This doesn't seem right label Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants