Code Monkey home page Code Monkey logo

vue-router-layout's Issues

ESM Builder Compatibility

I am using Vue CLI and would like to generate the app as an EMS module, however after connecting and configuring
vue-router-layout i am getting error:

ReferenceError: importScripts is not defined
    i main.mjs:1
    e main.mjs:1
    e main.mjs:1
    e main.mjs:1
    index index.js:2
    extractComponentsGuards vue-router.esm-bundler.js:2010
    navigate vue-router.esm-bundler.js:3089
    promise callback*navigate vue-router.esm-bundler.js:3084
    pushWithRedirect vue-router.esm-bundler.js:2979
    push vue-router.esm-bundler.js:2915
    install vue-router.esm-bundler.js:3329
    use runtime-core.esm-bundler.js:3808
    <anonymous> main.js:22
    433 main.mjs:1
    __webpack_require__ main.mjs:1
    <anonymous> main.mjs:1
[vue-router.esm-bundler.js:3248](webpack://website/node_modules/vue-router/dist/vue-router.esm-bundler.js?ec2d)
[Vue Router warn]: Unexpected error when starting the router: ReferenceError: importScripts is not defined
    i main.mjs:1
    e main.mjs:1
    e main.mjs:1
    e main.mjs:1
    index index.js:2
    extractComponentsGuards vue-router.esm-bundler.js:2010
    navigate vue-router.esm-bundler.js:3089
    promise callback*navigate vue-router.esm-bundler.js:3084
    pushWithRedirect vue-router.esm-bundler.js:2979
    push vue-router.esm-bundler.js:2915
    install vue-router.esm-bundler.js:3329
    use runtime-core.esm-bundler.js:3808
    <anonymous> main.js:22
    433 main.mjs:1
    __webpack_require__ main.mjs:1
    <anonymous> main.mjs:1

vue.config.cjs

module.exports = {
  configureWebpack: {
    target: "webworker",
    output: {
      filename: "[name].mjs",
      chunkFilename: "[name].mjs",
      chunkFormat: "array-push",
      library: {
        type: "module",
      },
    },
    mode: "production",
    entry: "./src/main.js",
    optimization: {
      splitChunks: false,
    },
    experiments: {
      outputModule: true,
    },
  },
  filenameHashing: false,
  pluginOptions: {
    autoRouting: {
      chunkNamePrefix: "page-",
    },
  },
};

babel.config.cjs

module.exports = {
  presets: ["@vue/cli-plugin-babel/preset"],
};

src/router/index.js

import { createRouter, createWebHistory } from "vue-router";
import routes from "vue-auto-routing";
import { createRouterLayout } from "vue-router-layout";

const RouterLayout = createRouterLayout((layout) => {
  return import("@/layouts/" + layout + ".vue");
});

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes: [
    {
      path: "/",
      component: RouterLayout,
      children: routes,
    },
  ],
});

export default router;

src/main.js

import { createApp, h } from "vue";
import App from "@/App.vue";
import router from "@/router";

const app = createApp({
  render() {
    return h(App);
  },
});

app.use(router);

app.mount("#app");

Defining the layout via an object errors out

In my home page I have specified a specific layout to use as such:

<script>
import HelloWorld from '@/components/HelloWorld.vue'
export default {
  name: 'home',
  layout: {
    name: 'public',
    props: {
      pageTitle: 'Search',
    },
  },
  components: {
    HelloWorld
  }
}
</script>

This results in no page rendered and this error in the console:

Uncaught (in promise) Error: Cannot find module './[object Object].vue'
    at eval (eval at ./src/layouts lazy recursive ^\.\/.*\.vue$ (app.js:1053), <anonymous>:15:12)

However, specifying the layout using a string works fine:

<script>
import HelloWorld from '@/components/HelloWorld.vue'
export default {
  name: 'home',
  layout: 'public',
  components: {
    HelloWorld
  }
}
</script>

I'd really like to be able to pass props. Any ideas? Thanks!

How to sovle Vite dynamic import problem?

|  Vue.use(Router);
6  |  const RouterLayout = createRouterLayout((layout) => {
7  |    return import("@/layouts/" + layout + ".vue");
   |                  ^
8  |  });
9  |  const router = new Router({
The above dynamic import cannot be analyzed by vite.
See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.

This plugin works fine with webpack but when I try to switch to vite, this problem happens and I dont know how to resolve it.
Please give me some help, thanks a lot!

keep-alive not work

when use vue-router-layout, keep-alive of components not work.

app.vue

<template>
     <div>
        <keep-alive include="home,about" :max="10">
             <router-view />
        </keep-alive>
    </div>
</template>

it can't keep the pages/home.vue and pages/about.vue alive.

home.vue

<template>
     <div>
        home page
    </div>
</template>
<script>
    export default {
        name: 'home'
    }
</script>

add nested: false in vue.config.js, it worked.

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.