Git Product home page Git Product logo

Comments (6)

yangjiakai avatar yangjiakai commented on June 8, 2024 1

@cgisky1980
页面清理之后精简版也发不了
这几天在集中完善nuxt3版本,一边进行迁移一边也在重构,这段时间重心可能会放在nuxt3版本了,自动生成侧边栏,我抽空添加到nuxt版本上吧

from lux-ui.

cgisky1980 avatar cgisky1980 commented on June 8, 2024

我自己改写 apps.routes.ts 实现了一下路由自动加载,不过 没有 vite-plugin-pages 强大,没实现 /:id 这样的路由,vpp 插件可以实现。

const metaRouters = import.meta.glob("@/views/demos/**/App.vue", {
  eager: true,
});

export const routes: Array<{
  path: string;
  meta: {
    requiresAuth: boolean;
    layout: string;
    category: string;
  };
  component: () => Promise<any>;
  children: Array<{
    path: string;
    redirect?: string;
    name?: string;
    component?: () => Promise<any>;
  }>;
}> = [];

Object.keys(metaRouters).forEach((item) => {
  let dirname = item.match(/\/src\/views\/demos\/(\S*)\/App.vue/);

  if (dirname !== null && dirname[1] !== null && dirname[0] !== null) {
    // let rr = "/src/views/demos/" + dirname[1] + "/Routes.ts";
    let routs = {
      path: "/demos/" + dirname[1],
      meta: {
        requiresAuth: true,
        layout: "ui",
        category: "DEMOS",
      },
      component: () => import(dirname[0]),
      children: [] as Array<{
        path: string;
        redirect?: string;
        name?: string;
        component?: () => Promise<any>;
      }>,
    };
 


    let pagesroutes: Array<{
      path: string;
      redirect?: string;
      name?: string;
      component?: () => Promise<any>;
    }> = [
      {
        path: "",
        redirect: "/demos/" + dirname[1] + "/main",
      },
    ];
 
    const pageR = import.meta.glob("/src/views/demos/*/pages/*.vue", {
      eager: true,
    });

    Object.keys(pageR).forEach((item) => {
 
      const pagesDirRegex = new RegExp(`\\/src\\/views\\/demos\\/${dirname[1]}\\/pages\\/(\\S*)\\.vue`);
      const matchResult = item.match(pagesDirRegex);
      if (matchResult) {
        // 匹配到.vue文件路径
        // console.log(matchResult[0]);
        // 进一步处理该路径
        let pagesroute = {
          path: matchResult[1],
          component: () => import(matchResult[0]),
          name: dirname[1] +'-'+matchResult[1],
        };
  
        pagesroutes.push(pagesroute);
      }
 
    });
    routs.children = pagesroutes;
    routes.push(routs);
  }
});
export default routes;```

from lux-ui.

yangjiakai avatar yangjiakai commented on June 8, 2024

这个我先看一下,通过子目录生成侧边栏的话,我觉得还是nuxt3版本添加这个功能比较合适,这个项目说实话pages页面比较混乱且数量多,实现这个成本巨大

from lux-ui.

cgisky1980 avatar cgisky1980 commented on June 8, 2024

@yangjiakai 我自己使用的话 pages 都清理了。 目前的项目结构,要清理或者添加新的页面 都很麻烦,
需要 locales 中N个文件处理 、router 处理 、 navigation.ts 还有 menu中处理。 nuxt3版本 就很清爽

以后再做迁移吧

from lux-ui.

cgisky1980 avatar cgisky1980 commented on June 8, 2024

nuxt3 好像本身就带自动路由了

from lux-ui.

cgisky1980 avatar cgisky1980 commented on June 8, 2024

我自己写的那玩意 dev可以 打包的时候 那几个VUE没编译进去 还是用vite-plugin-pages

from lux-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.