diff --git a/.changesets/11542.md b/.changesets/11542.md new file mode 100644 index 000000000000..90150cd45623 --- /dev/null +++ b/.changesets/11542.md @@ -0,0 +1,5 @@ +- feat(cli): Make scaffolded layout routing type-safe (#11542) by @Tobbe + +With this feature we now make sure only valid route names are passed as `titleTo` and `buttonTo` props to the scaffolded layout. + +This also means you get helpful code completion when typing out the prop values diff --git a/__fixtures__/test-project/web/src/layouts/ScaffoldLayout/ScaffoldLayout.tsx b/__fixtures__/test-project/web/src/layouts/ScaffoldLayout/ScaffoldLayout.tsx index 2912b56706d6..f4daba67e35a 100644 --- a/__fixtures__/test-project/web/src/layouts/ScaffoldLayout/ScaffoldLayout.tsx +++ b/__fixtures__/test-project/web/src/layouts/ScaffoldLayout/ScaffoldLayout.tsx @@ -3,9 +3,9 @@ import { Toaster } from '@redwoodjs/web/toast' type LayoutProps = { title: string - titleTo: string + titleTo: keyof typeof routes buttonLabel: string - buttonTo: string + buttonTo: keyof typeof routes children: React.ReactNode } diff --git a/packages/cli/src/commands/generate/scaffold/__tests__/__snapshots__/scaffold.test.js.snap b/packages/cli/src/commands/generate/scaffold/__tests__/__snapshots__/scaffold.test.js.snap index e520ac5a360d..8b2e1bc9b38e 100644 --- a/packages/cli/src/commands/generate/scaffold/__tests__/__snapshots__/scaffold.test.js.snap +++ b/packages/cli/src/commands/generate/scaffold/__tests__/__snapshots__/scaffold.test.js.snap @@ -2440,9 +2440,9 @@ import { Toaster } from '@redwoodjs/web/toast' type LayoutProps = { title: string - titleTo: string + titleTo: keyof typeof routes buttonLabel: string - buttonTo: string + buttonTo: keyof typeof routes children: React.ReactNode } diff --git a/packages/cli/src/commands/generate/scaffold/__tests__/__snapshots__/scaffoldNoNest.test.js.snap b/packages/cli/src/commands/generate/scaffold/__tests__/__snapshots__/scaffoldNoNest.test.js.snap index 2f5c79721d85..672d3167e6b5 100644 --- a/packages/cli/src/commands/generate/scaffold/__tests__/__snapshots__/scaffoldNoNest.test.js.snap +++ b/packages/cli/src/commands/generate/scaffold/__tests__/__snapshots__/scaffoldNoNest.test.js.snap @@ -1500,9 +1500,9 @@ import { Toaster } from '@redwoodjs/web/toast' type LayoutProps = { title: string - titleTo: string + titleTo: keyof typeof routes buttonLabel: string - buttonTo: string + buttonTo: keyof typeof routes children: React.ReactNode } diff --git a/packages/cli/src/commands/generate/scaffold/templates/layouts/ScaffoldLayout.tsx.template b/packages/cli/src/commands/generate/scaffold/templates/layouts/ScaffoldLayout.tsx.template index 2912b56706d6..f4daba67e35a 100644 --- a/packages/cli/src/commands/generate/scaffold/templates/layouts/ScaffoldLayout.tsx.template +++ b/packages/cli/src/commands/generate/scaffold/templates/layouts/ScaffoldLayout.tsx.template @@ -3,9 +3,9 @@ import { Toaster } from '@redwoodjs/web/toast' type LayoutProps = { title: string - titleTo: string + titleTo: keyof typeof routes buttonLabel: string - buttonTo: string + buttonTo: keyof typeof routes children: React.ReactNode }