-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…polvallverdu) Fixes #715 --------- Co-authored-by: Jan Amann <[email protected]>
- Loading branch information
1 parent
5cb9506
commit 6508ddc
Showing
11 changed files
with
408 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/next-intl/src/navigation/react-client/clientPermanentRedirect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import useLocale from '../../react-client/useLocale'; | ||
import {LocalePrefix, ParametersExceptFirst} from '../../shared/types'; | ||
import basePermanentRedirect from '../shared/basePermanentRedirect'; | ||
|
||
export default function clientPermanentRedirect( | ||
params: {localePrefix?: LocalePrefix; pathname: string}, | ||
...args: ParametersExceptFirst<typeof basePermanentRedirect> | ||
) { | ||
let locale; | ||
try { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context here is fine, since `redirect` should be called during render | ||
locale = useLocale(); | ||
} catch (e) { | ||
throw new Error( | ||
process.env.NODE_ENV !== 'production' | ||
? '`permanentRedirect()` can only be called during render. To redirect in an event handler or similar, you can use `useRouter()` instead.' | ||
: undefined | ||
); | ||
} | ||
|
||
return basePermanentRedirect({...params, locale}, ...args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/next-intl/src/navigation/react-server/serverPermanentRedirect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {getRequestLocale} from '../../server/react-server/RequestLocale'; | ||
import {LocalePrefix, ParametersExceptFirst} from '../../shared/types'; | ||
import basePermanentRedirect from '../shared/basePermanentRedirect'; | ||
|
||
export default function serverPermanentRedirect( | ||
params: {pathname: string; localePrefix?: LocalePrefix}, | ||
...args: ParametersExceptFirst<typeof basePermanentRedirect> | ||
) { | ||
const locale = getRequestLocale(); | ||
return basePermanentRedirect({...params, locale}, ...args); | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/next-intl/src/navigation/shared/basePermanentRedirect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {permanentRedirect as nextPermanentRedirect} from 'next/navigation'; | ||
import { | ||
AllLocales, | ||
LocalePrefix, | ||
ParametersExceptFirst | ||
} from '../../shared/types'; | ||
import {prefixPathname} from '../../shared/utils'; | ||
|
||
export default function basePermanentRedirect( | ||
params: { | ||
pathname: string; | ||
locale: AllLocales[number]; | ||
localePrefix?: LocalePrefix; | ||
}, | ||
...args: ParametersExceptFirst<typeof nextPermanentRedirect> | ||
) { | ||
const localizedPathname = | ||
params.localePrefix === 'never' | ||
? params.pathname | ||
: prefixPathname(params.locale, params.pathname); | ||
return nextPermanentRedirect(localizedPathname, ...args); | ||
} |
Oops, something went wrong.