Skip to content

Instantly share code, notes, and snippets.

@dlodeprojuicer
Created April 23, 2020 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlodeprojuicer/1dc807df7fdb352fc7cb96bd22d52926 to your computer and use it in GitHub Desktop.
Save dlodeprojuicer/1dc807df7fdb352fc7cb96bd22d52926 to your computer and use it in GitHub Desktop.
Dynamic Router Step 2b
let routes = [];
requireModule.keys().map(file => {
// filename string example `./Home.vue`
const moduleName = file.split("/")[1].split(".vue")[0];
const url = moduleName.replace(/([a-zA-Z])(?=[A-Z])/g, "$1-").toLowerCase();
routes.push({
path: `/${url}`,
name: url,
component: () => import(`./views/${moduleName}.vue`)
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment