diff --git a/src/template.ts b/src/template.ts index 5056a9e1..38c34732 100644 --- a/src/template.ts +++ b/src/template.ts @@ -21,9 +21,9 @@ function exportedQuery(ctx: Context) { } function routes(ctx: Context) { - const routes = ctx.routes.map(({ route, params, fileName }) => + const routes = ctx.routes.map(({ id, route, params, fileName }) => `"${route}": { - id: '${route}', + id: '${id}', params: ${params.length > 0 ? `{${params.map(param => `${param}: string | number`).join('; ')}}` : 'never'}, query: ExportedQuery, }` diff --git a/tests/__snapshots__/build.test.ts.snap b/tests/__snapshots__/build.test.ts.snap index d63f9d85..f77f3a0c 100644 --- a/tests/__snapshots__/build.test.ts.snap +++ b/tests/__snapshots__/build.test.ts.snap @@ -10,137 +10,137 @@ exports[`gen route types 1`] = ` export interface Routes { "/": { - id: '/', + id: 'root', params: never, query: ExportedQuery, }, "/:lang?/about": { - id: '/:lang?/about', + id: 'routes/($lang).about', params: {lang?: string | number}, query: ExportedQuery, }, "/admin": { - id: '/admin', + id: 'routes/admin._index', params: never, query: ExportedQuery, }, "/admin/episodes": { - id: '/admin/episodes', + id: 'routes/admin.episodes._index', params: never, query: ExportedQuery, }, "/admin/episodes/:id": { - id: '/admin/episodes/:id', + id: 'routes/admin.episodes.$id._index', params: {id: string | number}, query: ExportedQuery, }, "/admin/episodes/:id/comments": { - id: '/admin/episodes/:id/comments', + id: 'routes/admin.episodes.$id.comments', params: {id: string | number}, query: ExportedQuery, }, "/admin/episodes/new": { - id: '/admin/episodes/new', + id: 'routes/admin.episodes.new', params: never, query: ExportedQuery, }, "/api/:id.json": { - id: '/api/:id.json', + id: 'routes/api.$id[.]json', params: {id: string | number}, query: ExportedQuery, }, "/auth": { - id: '/auth', + id: 'routes/auth._auth', params: never, query: ExportedQuery, }, "/auth/login": { - id: '/auth/login', + id: 'routes/auth._auth.login', params: never, query: ExportedQuery, }, "/blog/rss.xml": { - id: '/blog/rss.xml', + id: 'routes/blog.rss[.]xml', params: never, query: ExportedQuery, }, "/chats/:season/:episode": { - id: '/chats/:season/:episode', + id: 'routes/chats_.$season.$episode', params: {season: string | number; episode: string | number}, query: ExportedQuery, }, "/chats/:season/:episode/:slug": { - id: '/chats/:season/:episode/:slug', + id: 'routes/chats_.$season.$episode.$slug', params: {season: string | number; episode: string | number; slug: string | number}, query: ExportedQuery, }, "/credits": { - id: '/credits', + id: 'routes/credits', params: never, query: ExportedQuery, }, "/home": { - id: '/home', + id: 'routes/(static).home', params: never, query: ExportedQuery, }, "/jokes": { - id: '/jokes', + id: 'routes/jokes._index', params: never, query: ExportedQuery, }, "/jokes/:jokeId": { - id: '/jokes/:jokeId', + id: 'routes/jokes.$jokeId', params: {jokeId: string | number}, query: ExportedQuery, }, "/people/:personId": { - id: '/people/:personId', + id: 'routes/people.$personId', params: {personId: string | number}, query: ExportedQuery, }, "/people/:personId/:planId/remove-plan": { - id: '/people/:personId/:planId/remove-plan', + id: 'routes/people.$personId.$planId.remove-plan', params: {personId: string | number; planId: string | number}, query: ExportedQuery, }, "/posts": { - id: '/posts', + id: 'routes/posts._index', params: never, query: ExportedQuery, }, "/posts/:id": { - id: '/posts/:id', + id: 'routes/posts.$id', params: {id: string | number}, query: ExportedQuery, }, "/posts/*": { - id: '/posts/*', + id: 'routes/posts.$', params: {"*": string | number}, query: ExportedQuery, }, "/posts/delete": { - id: '/posts/delete', + id: 'routes/posts.delete', params: never, query: ExportedQuery, }, "/s/:query": { - id: '/s/:query', + id: 'routes/s.$query', params: {query: string | number}, query: ExportedQuery, }, "/sign-in/*": { - id: '/sign-in/*', + id: 'routes/sign-in.$', params: {"*": string | number}, query: ExportedQuery, }, "/somewhere/cool/*": { - id: '/somewhere/cool/*', + id: 'catchall', params: {"*": string | number}, query: ExportedQuery, }, "/static/home": { - id: '/static/home', + id: 'routes/(static).home', params: never, query: ExportedQuery, }