Skip to content

Commit

Permalink
Upgrade example-app-router-playground and get rid of middleware war…
Browse files Browse the repository at this point in the history
…nings by making sure the middleware doesn't import from anything React-specific
  • Loading branch information
amannn committed May 24, 2024
1 parent 5f3002f commit b746959
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 41 deletions.
6 changes: 3 additions & 3 deletions examples/example-app-router-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"dependencies": {
"lodash": "^4.17.21",
"ms": "2.1.3",
"next": "^14.2.3",
"next": "15.0.0-rc.0",
"next-intl": "latest",
"react": "^18.3.0",
"react-dom": "^18.3.0"
"react": "19.0.0-rc-f994737d14-20240522",
"react-dom": "19.0.0-rc-f994737d14-20240522"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
Expand Down
33 changes: 33 additions & 0 deletions examples/example-app-router-playground/src/config.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {Pathnames} from 'next-intl/navigation';

export const defaultLocale = 'en';

export const locales = ['en', 'de', 'es', 'ja'] as const;

export const localePrefix =
process.env.NEXT_PUBLIC_LOCALE_PREFIX === 'never' ? 'never' : 'as-needed';

export const pathnames = {
'/': '/',
'/client': '/client',
'/client/redirect': '/client/redirect',
'/nested': {
en: '/nested',
de: '/verschachtelt',
es: '/anidada',
ja: '/ネスト'
},
'/redirect': '/redirect',
'/news/[articleId]': {
en: '/news/[articleId]',
de: '/neuigkeiten/[articleId]',
es: '/noticias/[articleId]',
ja: '/ニュース/[articleId]'
},
'/news/just-in': {
en: '/news/just-in',
de: '/neuigkeiten/aktuell',
es: '/noticias/justo-en',
ja: '/ニュース/現在'
}
} satisfies Pathnames<typeof locales>;
2 changes: 1 addition & 1 deletion examples/example-app-router-playground/src/i18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {headers} from 'next/headers';
import {notFound} from 'next/navigation';
import {getRequestConfig} from 'next-intl/server';
import defaultMessages from '../messages/en.json';
import {locales} from './navigation';
import {locales} from './config';

export default getRequestConfig(async ({locale}) => {
// Validate that the incoming `locale` parameter is valid
Expand Down
2 changes: 1 addition & 1 deletion examples/example-app-router-playground/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import createMiddleware from 'next-intl/middleware';
import {locales, pathnames, localePrefix, defaultLocale} from './navigation';
import {locales, pathnames, localePrefix, defaultLocale} from './config';

export default createMiddleware({
defaultLocale,
Expand Down
38 changes: 2 additions & 36 deletions examples/example-app-router-playground/src/navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,5 @@
import {
createLocalizedPathnamesNavigation,
Pathnames
} from 'next-intl/navigation';

export const defaultLocale = 'en';

export const locales = ['en', 'de', 'es', 'ja'] as const;

export const localePrefix =
process.env.NEXT_PUBLIC_LOCALE_PREFIX === 'never' ? 'never' : 'as-needed';

export const pathnames = {
'/': '/',
'/client': '/client',
'/client/redirect': '/client/redirect',
'/nested': {
en: '/nested',
de: '/verschachtelt',
es: '/anidada',
ja: '/ネスト'
},
'/redirect': '/redirect',
'/news/[articleId]': {
en: '/news/[articleId]',
de: '/neuigkeiten/[articleId]',
es: '/noticias/[articleId]',
ja: '/ニュース/[articleId]'
},
'/news/just-in': {
en: '/news/just-in',
de: '/neuigkeiten/aktuell',
es: '/noticias/justo-en',
ja: '/ニュース/現在'
}
} satisfies Pathnames<typeof locales>;
import {createLocalizedPathnamesNavigation} from 'next-intl/navigation';
import {locales, localePrefix, pathnames} from './config';

export const {Link, redirect, usePathname, useRouter} =
createLocalizedPathnamesNavigation({
Expand Down

0 comments on commit b746959

Please sign in to comment.