Skip to content

Commit 3388c30

Browse files
authored
feat: export routes object for dynamic menu generation (#166)
1 parent 393f22b commit 3388c30

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

.changeset/rude-seals-reflect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sv-router': patch
3+
---
4+
5+
Export routes object for dynamic menu generation

src/gen/generate-router-code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export function createRouterCode(routes, routesPath, { allLazy = false, js = fal
216216
`import { createRouter } from 'sv-router';`,
217217
...imports,
218218
'',
219-
`const routes = ${stringifiedRoutes};`,
219+
`export const routes = ${stringifiedRoutes};`,
220220
...(js ? [] : ['export type Routes = typeof routes;']),
221221
'export const { p, navigate, isActive, preload, route } = createRouter(routes);',
222222
'',

tests/generate-router-code.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Index from '../a/fake/path/index.svelte';
2020
import PostsStatic from '../a/fake/path/posts.static.svelte';
2121
import PostsNolayout from '../a/fake/path/posts.(nolayout).svelte';
2222
23-
const routes = {
23+
export const routes = {
2424
'*notfound': () => import('../a/fake/path/[...notfound].lazy.svelte'),
2525
'/about': About,
2626
'/': Index,
@@ -49,7 +49,7 @@ import postsMeta from '../a/fake/path/posts/meta.svelte';
4949
import postsCommentsHooks from '../a/fake/path/posts/comments/hooks.svelte';
5050
import postsCommentsMeta from '../a/fake/path/posts/comments/meta';
5151
52-
const routes = {
52+
export const routes = {
5353
'*notfound': () => import('../a/fake/path/[...notfound].lazy.svelte'),
5454
'/about': About,
5555
'/': Index,
@@ -285,7 +285,7 @@ import GroupLayout from './routes/_group/layout.svelte';
285285
import groupHooks from './routes/_group/hooks';
286286
import groupMeta from './routes/_group/meta';
287287
288-
const routes = {
288+
export const routes = {
289289
'/': Index,
290290
'/about': About,
291291
'/posts': {
@@ -324,7 +324,7 @@ import postsCommentsMeta from './routes/posts/comments/meta.svelte';
324324
import groupHooks from './routes/_group/hooks';
325325
import groupMeta from './routes/_group/meta';
326326
327-
const routes = {
327+
export const routes = {
328328
'/': () => import('./routes/index.svelte'),
329329
'/about': () => import('./routes/about.svelte'),
330330
'/posts': {
@@ -358,7 +358,7 @@ export const { p, navigate, isActive, preload, route } = createRouter(routes);
358358
expect(result).toBe(`import { createRouter } from 'sv-router';
359359
import Index from './routes/index.svelte';
360360
361-
const routes = {
361+
export const routes = {
362362
'/': Index
363363
};
364364
export const { p, navigate, isActive, preload, route } = createRouter(routes);

0 commit comments

Comments
 (0)