fix: dynamic routes must start with an underscore

Folders or files within `pages/` should only lead to dynamic routes, if they start with an underscore.
Previously, folders like `some_folder` would lead to a route parameter `folder` being introduced.
This commit is contained in:
David Müller 2018-03-11 07:09:27 +07:00
parent f57096e572
commit 751aae38d4

View File

@ -297,8 +297,13 @@ export const createRoutes = function createRoutes(files, srcDir, pagesDir) {
if (key === 'index' && i + 1 === keys.length) {
route.path += i > 0 ? '' : '/'
} else {
route.path += '/' + (key === '_' ? '*' : key.replace('_', ':'))
if (key !== '_' && key.indexOf('_') !== -1) {
route.path += '/' +
(key === '_'
? '*'
: key.indexOf('_') === 0
? key.replace('_', ':')
: key)
if (key !== '_' && key.indexOf('_') === 0) {
route.path += '?'
}
}