Skip to content

Commit

Permalink
don't use lookbehind regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed May 20, 2024
1 parent 7c552fa commit 939a036
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/start/src/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ function defineRoutes(fileRoutes: Route[]) {
});

if (!parentRoute) {
routes.push({
...route,
id,
path: id
// strip out escape group for escaping nested routes - e.g. foo(bar) -> foo
.replace(/\/\([^)/]+\)/g, "")
.replace(/\([^)/]+\)/g, "")
// replace . with / for flat routes - e.g. foo.bar -> foo/bar
// ensures that ... of splat routes is not replaced
.replace(/(?<!\.)\.(?!\.)/g, "/")
});
const path = id
// strip out escape group for escaping nested routes - e.g. foo(bar) -> foo
.replace(/\/\([^)/]+\)/g, "")
.replace(/\([^)/]+\)/g, "")
// replace . with / for flat routes - e.g. foo.bar -> foo/bar
.replace(/\./g, "/")
// converts any splat route ... that got replaced back from ///
// this could be avoided with a lookbehind regex but safar has only supported them since mid 2023
.replace("///", "...");

routes.push({ ...route, id, path });
return routes;
}
processRoute(
Expand Down

0 comments on commit 939a036

Please sign in to comment.