Skip to content

Commit

Permalink
Set slug=key if no slug for each page in Router
Browse files Browse the repository at this point in the history
  • Loading branch information
fdesjardins committed Oct 7, 2023
1 parent 2aef649 commit 9e42c02
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import { ErrorBoundaryFallback } from './components/error-boundary-fallback/Erro
const pageIndex = Object.keys(pages)
.map((key) => ({ key, ...pages[key] }))
.filter((x) => !!x.meta)
.map((x) => {
if (!x.meta.slug) {
x.meta.slug = x.key
}
return x
})
.sort((a, b) => a.meta.title.localeCompare(b.meta.title))

const PageIndex = ss.array(
Expand Down Expand Up @@ -44,8 +50,8 @@ const Router = ({ children }) => {
<Route path="/" element={<Home pageIndex={pageIndex} />} />
{pageIndex.map(({ key, meta, options, init }) => (
<Route
key={meta.slug ?? key}
path={meta.slug ?? key}
key={meta.slug || key}
path={meta.slug || key}
element={<Page meta={meta} options={options} init={init} />}
/>
))}
Expand Down

0 comments on commit 9e42c02

Please sign in to comment.