add optional param by default

This commit is contained in:
Alexandre Chopin 2016-12-20 17:30:43 +01:00
parent 4c3f7abb1d
commit 904c4e5793

View File

@ -229,8 +229,15 @@ function createRoutes (files, srcDir) {
}
function cleanChildrenRoutes (routes, isChild = false) {
let isOptional = true
routes.forEach((route) => {
route.path = (isChild) ? route.path.replace('/', '') : route.path
if (route.path === '') {
isOptional = false
}
if (isChild && isOptional && route.path.includes(':')) {
route.path += '?'
}
if (route.children) {
delete route.name
route.children = cleanChildrenRoutes(route.children, true)