Skip to content

Commit

Permalink
refactor: better route path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
datsfilipe committed Jul 26, 2024
1 parent 92c1a0f commit ae58a91
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/app/lib/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ for (const path in pages) {
}
}

const fullPath: string = isSlugPage ? `/${slugPath}` : `/${normalizedFilename}`

routes.push({
path: isSlugPage ? `/${slugPath}` : `/${normalizedFilename}`,
layoutPath: layoutname === 'common' ? '/' : fullPath.split('/')[1],
routePath: layoutname === 'common' ? fullPath : fullPath.split('/')[2],
Element: pages[path].default,
ErrorElement: Object.values(errorPage)[0]?.default ?? (() => <></>),
Layout: Layout,
Expand All @@ -88,11 +91,12 @@ for (const path in pages) {

const router = createBrowserRouter(
routes.map(({ Element, Layout, ErrorElement, ...rest }) => ({
path: '/',
path: rest.layoutPath,
element: <Layout />,
children: [
{
...rest,
path: rest.routePath,
element: <Element />,
errorElement: <ErrorElement />
}
Expand Down

0 comments on commit ae58a91

Please sign in to comment.