@@ -114,25 +114,14 @@ function templateRSCPage({
114114 ${ code }
115115
116116 export default async function __Next_Translate_new__${ hash } __(props) {
117- const params = await props.params
118- const searchParams = await props.searchParams
119- const detectedLang = params?.lang ?? searchParams?.lang
120-
121- if (detectedLang === 'favicon.ico') return <${ pageVariableName } {...props} />
122-
123- ${
124- routeType !== '/page'
125- ? // Related with https://github.com/aralroca/next-translate/issues/1090
126- // Early return to avoid conflicts with /layout or /loading that don't have detectedLang
127- `if (globalThis.__NEXT_TRANSLATE__ && !detectedLang) return <${ pageVariableName } {...props} />`
128- : ''
129- }
130-
117+ const params = (await props?.params) || {}
118+ const searchParams = (await props?.searchParams) || {}
119+ const lang = params.lang || searchParams.lang
131120 const config = {
132121 ...${ INTERNAL_CONFIG_KEY } ,
133- locale: detectedLang ?? ${ INTERNAL_CONFIG_KEY } .defaultLocale,
122+ locale: lang ?? ${ INTERNAL_CONFIG_KEY } .defaultLocale,
134123 loaderName: 'server ${ routeType } ',
135- pathname: '${ pathname } '
124+ pathname: '${ pathname } '.replace(/\\[([^\\]]+)\\]/g, (m, key) => (key === 'lang' ? '[lang]' : (params[key] || m)))
136125 }
137126
138127 const { __lang, __namespaces } = await __loadNamespaces({ ...config, ${ addLoadLocalesFrom (
@@ -181,25 +170,13 @@ function templateRCCPage({
181170
182171 export default function __Next_Translate_new__${ hash } __(props) {
183172 const searchParams = __useSearchParams()
184- const params = __useParams()
185- const detectedLang = params.lang ?? searchParams.get('lang')
186-
187- if (detectedLang === 'favicon.ico') return <${ pageVariableName } {...props} />
188-
189- ${
190- routeType !== '/page'
191- ? // Related with https://github.com/aralroca/next-translate/issues/1090
192- // Early return to avoid conflicts with /layout or /loading that don't have detectedLang
193- `if (globalThis.__NEXT_TRANSLATE__ && !detectedLang) return <${ pageVariableName } {...props} />`
194- : ''
195- }
196-
197- const lang = detectedLang ?? ${ INTERNAL_CONFIG_KEY } .defaultLocale
173+ const params = __useParams() || {}
174+ const lang = params.lang || searchParams.get('lang')
198175 const config = {
199176 ...${ INTERNAL_CONFIG_KEY } ,
200- locale: lang,
177+ locale: lang || ${ INTERNAL_CONFIG_KEY } .defaultLocale ,
201178 loaderName: 'client ${ routeType } ',
202- pathname: '${ pathname } ',
179+ pathname: '${ pathname } '.replace(/\\[([^\\]]+)\\]/g, (m, key) => (key === 'lang' ? '[lang]' : (params[key] || m))) ,
203180 }
204181
205182 return (
0 commit comments