Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
srcDir: this.template.dir + '/pages',
routeNameSplitter,
trailingSlash
})
} else if (this._nuxtPages) {
// Use nuxt.js createRoutes bases on pages/
const files = {}
const ext = new RegExp(`\\.(${this.supportedExtensions.join('|')})$`)
for (const page of await this.resolveFiles(this.options.dir.pages)) {
const key = page.replace(ext, '')
// .vue file takes precedence over other extensions
if (/\.vue$/.test(page) || !files[key]) {
files[key] = page.replace(/(['"])/g, '\\$1')
}
}
templateVars.router.routes = createRoutes({
files: Object.values(files),
srcDir: this.options.srcDir,
pagesDir: this.options.dir.pages,
routeNameSplitter,
supportedExtensions: this.supportedExtensions,
trailingSlash
})
} else { // If user defined a custom method to create routes
templateVars.router.routes = await this.options.build.createRoutes(
this.options.srcDir
)
}
await this.nuxt.callHook(
'build:extendRoutes',
templateVars.router.routes,
async resolveRoutes ({ templateVars }) {
consola.debug('Generating routes...')
const { routeNameSplitter, trailingSlash } = this.options.router
if (this._defaultPage) {
templateVars.router.routes = createRoutes({
files: ['index.vue'],
srcDir: this.template.dir + '/pages',
routeNameSplitter,
trailingSlash
})
} else if (this._nuxtPages) {
// Use nuxt.js createRoutes bases on pages/
const files = {}
const ext = new RegExp(`\\.(${this.supportedExtensions.join('|')})$`)
for (const page of await this.resolveFiles(this.options.dir.pages)) {
const key = page.replace(ext, '')
// .vue file takes precedence over other extensions
if (/\.vue$/.test(page) || !files[key]) {
files[key] = page.replace(/(['"])/g, '\\$1')
}
}