File tree Expand file tree Collapse file tree 5 files changed +15
-9
lines changed Expand file tree Collapse file tree 5 files changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -8,13 +8,13 @@ import Preview from './preview';
8
8
export const dynamicParams = true ;
9
9
10
10
export interface PreviewParams {
11
- slug : string ;
11
+ slug : string [ ] ;
12
12
}
13
13
14
14
export default async function Page ( { params } : { params : PreviewParams } ) {
15
- // will come in here as a relative path to the email
16
- // ex: authentication/ verify-password.tsx but encoded like authentication%20verify-password.tsx
17
- const slug = decodeURIComponent ( params . slug ) ;
15
+ // will come in here as segments of a relative path to the email
16
+ // ex: [' authentication', ' verify-password.tsx']
17
+ const slug = params . slug . join ( '/' ) ;
18
18
const emailsDirMetadata = await getEmailsDirectoryMetadata (
19
19
emailsDirectoryAbsolutePath ,
20
20
) ;
@@ -47,5 +47,5 @@ export default async function Page({ params }: { params: PreviewParams }) {
47
47
}
48
48
49
49
export function generateMetadata ( { params } : { params : PreviewParams } ) {
50
- return { title : `${ decodeURIComponent ( params . slug ) } — React Email` } ;
50
+ return { title : `${ params . slug . join ( '/' ) } — React Email` } ;
51
51
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change @@ -104,9 +104,15 @@ const getEmailSlugsFromEmailDirectory = (
104
104
. replace ( emailsDirectoryAbsolutePath , '' )
105
105
. trim ( ) ;
106
106
107
- const slugs = [ ] as string [ ] ;
107
+ const slugs = [ ] as Array < string > [ ] ;
108
108
emailDirectory . emailFilenames . forEach ( ( filename ) =>
109
- slugs . push ( path . join ( directoryPathRelativeToEmailsDirectory , filename ) ) ,
109
+ slugs . push (
110
+ path
111
+ . join ( directoryPathRelativeToEmailsDirectory , filename )
112
+ . split ( path . sep )
113
+ // sometimes it gets empty segments due to trailing slashes
114
+ . filter ( ( segment ) => segment . length > 0 ) ,
115
+ ) ,
110
116
) ;
111
117
emailDirectory . subDirectories . forEach ( ( directory ) => {
112
118
slugs . push (
@@ -136,7 +142,7 @@ const forceSSGForEmailPreviews = async (
136
142
) . map ( ( slug ) => ( { slug } ) ) ;
137
143
138
144
await fs . promises . appendFile (
139
- path . resolve ( builtPreviewAppPath , './src/app/preview/[slug]/page.tsx' ) ,
145
+ path . resolve ( builtPreviewAppPath , './src/app/preview/[... slug]/page.tsx' ) ,
140
146
`
141
147
142
148
export async function generateStaticParams() {
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ export const SidebarDirectoryChildren = (props: {
67
67
return (
68
68
< Link
69
69
href = { {
70
- pathname : `/preview/${ encodeURIComponent ( emailSlug ) } ` ,
70
+ pathname : `/preview/${ emailSlug } ` ,
71
71
search : searchParams . toString ( ) ,
72
72
} }
73
73
key = { emailSlug }
You can’t perform that action at this time.
0 commit comments