-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from Next.js Pages Router to App Router (#255)
## Ticket Resolves #66 ## Changes This is purely an architecture migration and nothing functionally should have changed. **Pages Router → App Router**: - `pages/_app.tsx` → `app/[locale]/layout.tsx` - `pages/index.tsx` → `app/[locale]/page.tsx` - `pages/health.tsx` → `app/[locale]/health/page.tsx` - `pages/api/hello.ts` → `app/api/hello/route.tsx` **Internationalized routing and locale detection**: App Router doesn't include built-in support for internationalized routing and locale detection like Pages Router. - Added Next.js Middleware (`src/middleware.ts`) to detect and store the user's preferred language, and routing them to `/es-US/*` when their preferred language is Spanish - Added `i18n/server.ts` to contain server-side configuration for the `next-intl` plugin. This makes locale strings available to all server components ## Context for reviewers - [See the related ADR](https://github.com/navapbc/template-application-nextjs/blob/main/docs/decisions/app/0008-app-router.md) for why we're moving towards App Router. - A page file is restricted in what it can export, hence why `view.tsx` exists instead of that component being colocated in the `page.tsx` file. [More context on this Next.js issue](vercel/next.js#53940 (comment)).
- Loading branch information
Showing
23 changed files
with
264 additions
and
209 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return <>healthy</>; | ||
} |
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,32 @@ | ||
/** | ||
* Root layout component, wraps all pages. | ||
* @see https://nextjs.org/docs/app/api-reference/file-conventions/layout | ||
*/ | ||
import { Metadata } from "next"; | ||
|
||
import Layout from "src/components/Layout"; | ||
|
||
import "src/styles/styles.scss"; | ||
|
||
export const metadata: Metadata = { | ||
icons: [`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/img/logo.svg`], | ||
}; | ||
|
||
interface LayoutProps { | ||
children: React.ReactNode; | ||
params: { | ||
locale: string; | ||
}; | ||
} | ||
|
||
export default function RootLayout({ children, params }: LayoutProps) { | ||
return ( | ||
<html lang={params.locale}> | ||
<body> | ||
{/* Separate layout component for the inner-body UI elements since Storybook | ||
and tests trip over the fact that this file renders an <html> tag */} | ||
<Layout locale={params.locale}>{children}</Layout> | ||
</body> | ||
</html> | ||
); | ||
} |
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,25 @@ | ||
import { Metadata } from "next"; | ||
import { isFeatureEnabled } from "src/services/feature-flags"; | ||
|
||
import { getTranslations } from "next-intl/server"; | ||
|
||
import { View } from "./view"; | ||
|
||
interface RouteParams { | ||
locale: string; | ||
} | ||
|
||
export async function generateMetadata({ params }: { params: RouteParams }) { | ||
const t = await getTranslations({ locale: params.locale }); | ||
const meta: Metadata = { | ||
title: t("home.title"), | ||
}; | ||
|
||
return meta; | ||
} | ||
|
||
export default async function Controller() { | ||
const isFooEnabled = await isFeatureEnabled("foo", "anonymous"); | ||
|
||
return <View isFooEnabled={isFooEnabled} />; | ||
} |
Oops, something went wrong.