Skip to content

Commit

Permalink
馃悰 Fix path generation to ensure relative paths
Browse files Browse the repository at this point in the history
Fixes #14
  • Loading branch information
kiliman committed Nov 10, 2022
1 parent 5d2fbf6 commit 1c2076e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/index.ts
Expand Up @@ -136,9 +136,9 @@ function getRoutes(
const routeChildren: DefineRouteChildren = () => {
for (let child of parentRoute!.children) {
getRoutes(parentMap, child.name, route)
const path = child.path.substring(
parentRoute!.routeInfo.path.length + 1,
)

let path = child.path.substring(parentRoute!.routeInfo.path.length)
if (path.startsWith('/')) path = path.substring(1)
route(path, child.file, { index: child.index })
}
}
Expand All @@ -157,6 +157,9 @@ export function getRouteInfo(
basePath?: string,
): RouteInfo | null {
let url = basePath ?? ''
if (url.startsWith('/')) {
url = url.substring(1)
}
// get extension
let ext = path.extname(routeFile)
// only process valid route files
Expand Down Expand Up @@ -218,7 +221,8 @@ function appendPathSegment(url: string, segment: string) {
// handle params
segment = segment === '$' ? '*' : `:${segment.substring(1)}`
}
url += '/' + segment
if (url) url += '/'
url += segment
}
return url
}
Expand Down

0 comments on commit 1c2076e

Please sign in to comment.