Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rude-seals-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv-router': patch
---

Export routes object for dynamic menu generation
2 changes: 1 addition & 1 deletion src/gen/generate-router-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export function createRouterCode(routes, routesPath, { allLazy = false, js = fal
`import { createRouter } from 'sv-router';`,
...imports,
'',
`const routes = ${stringifiedRoutes};`,
`export const routes = ${stringifiedRoutes};`,
...(js ? [] : ['export type Routes = typeof routes;']),
'export const { p, navigate, isActive, preload, route } = createRouter(routes);',
'',
Expand Down
10 changes: 5 additions & 5 deletions tests/generate-router-code.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Index from '../a/fake/path/index.svelte';
import PostsStatic from '../a/fake/path/posts.static.svelte';
import PostsNolayout from '../a/fake/path/posts.(nolayout).svelte';

const routes = {
export const routes = {
'*notfound': () => import('../a/fake/path/[...notfound].lazy.svelte'),
'/about': About,
'/': Index,
Expand Down Expand Up @@ -49,7 +49,7 @@ import postsMeta from '../a/fake/path/posts/meta.svelte';
import postsCommentsHooks from '../a/fake/path/posts/comments/hooks.svelte';
import postsCommentsMeta from '../a/fake/path/posts/comments/meta';

const routes = {
export const routes = {
'*notfound': () => import('../a/fake/path/[...notfound].lazy.svelte'),
'/about': About,
'/': Index,
Expand Down Expand Up @@ -285,7 +285,7 @@ import GroupLayout from './routes/_group/layout.svelte';
import groupHooks from './routes/_group/hooks';
import groupMeta from './routes/_group/meta';

const routes = {
export const routes = {
'/': Index,
'/about': About,
'/posts': {
Expand Down Expand Up @@ -324,7 +324,7 @@ import postsCommentsMeta from './routes/posts/comments/meta.svelte';
import groupHooks from './routes/_group/hooks';
import groupMeta from './routes/_group/meta';

const routes = {
export const routes = {
'/': () => import('./routes/index.svelte'),
'/about': () => import('./routes/about.svelte'),
'/posts': {
Expand Down Expand Up @@ -358,7 +358,7 @@ export const { p, navigate, isActive, preload, route } = createRouter(routes);
expect(result).toBe(`import { createRouter } from 'sv-router';
import Index from './routes/index.svelte';

const routes = {
export const routes = {
'/': Index
};
export const { p, navigate, isActive, preload, route } = createRouter(routes);
Expand Down