Created
April 23, 2020 10:30
-
-
Save dlodeprojuicer/1dc807df7fdb352fc7cb96bd22d52926 to your computer and use it in GitHub Desktop.
Dynamic Router Step 2b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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