Skip to content

Commit

Permalink
Update to next-intl@3.18.0 and use defineRouting
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed Aug 28, 2024
1 parent 0469003 commit 0a00684
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"next": "^14.1.0",
"next-intl": "^3.11.0",
"next-intl": "^3.18.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
4 changes: 2 additions & 2 deletions src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {notFound} from 'next/navigation';
import {getRequestConfig} from 'next-intl/server';
import {locales} from './navigation';
import {routing} from './routing';

export default getRequestConfig(async ({locale}) => {
// Validate that the incoming `locale` parameter is valid
if (!locales.includes(locale as any)) notFound();
if (!routing.locales.includes(locale as any)) notFound();

return {
messages: (await import(`../messages/${locale}.json`)).default
Expand Down
8 changes: 2 additions & 6 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import createMiddleware from 'next-intl/middleware';
import {locales, localePrefix, defaultLocale} from './navigation';
import {routing} from './routing';

export default createMiddleware({
defaultLocale,
locales,
localePrefix
});
export default createMiddleware(routing);

export const config = {
matcher: ['/', '/(en)/:path*']
Expand Down
14 changes: 0 additions & 14 deletions src/navigation.ts

This file was deleted.

10 changes: 10 additions & 0 deletions src/routing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {createSharedPathnamesNavigation} from 'next-intl/navigation';
import {defineRouting} from 'next-intl/routing'

export const routing = defineRouting({
locales: ['en'],
defaultLocale: 'en',
})

export const {Link, redirect, usePathname, useRouter} =
createSharedPathnamesNavigation(routing);

0 comments on commit 0a00684

Please sign in to comment.