Unverified Commit 49ef9782 authored by SamPhillemon's avatar SamPhillemon Committed by GitHub

updated the example of custom-routes-proxying to utilize the App Router (#68941)

This PR updates the custom-routes-proxying example to use the App
Router. Here are the changes that have been made:

- Renamed the "pages" folder to the "app" folder.
- Updated the routing for /, /about & /hello/[slug] files to align with
the App Router.
- Added the layout.tsx file as part of the App Router.
- Updated the package.json file.
- Updated the Readme file.

CC: @samcx

---------
Co-authored-by: 's avatarLee Robinson <me@leerob.io>
Co-authored-by: 's avatarsamcx <sam@vercel.com>
parent 0fc762c7
# Custom Routes Proxying Example # Custom Routes Proxying Example
This example shows the most basic example using Next.js' new custom routes feature to proxy requests to an upstream server. We have 3 pages: `pages/index.js`, `pages/about.js`, and `pages/hello/[slug].js`. All of these pages will be matched against Next.js and any other path will be proxied to the upstream server. This example shows the most basic example using Next.js' new custom routes feature to proxy requests to an upstream server. We have 3 pages: `app/page.tsx`, `app/about/page.tsx`, and `app/hello/[slug]/page.tsx`. All of these pages will be matched against Next.js and any other path will be proxied to the upstream server.
This approach is very helpful when you are trying to incrementally migrate your application to Next.js but still need to fallback to an existing application. You can add pages to your Next.js application one-by-one and then for non-migrated pages Next.js can proxy to the existing application until they are able to be migrated. This approach is very helpful when you are trying to incrementally migrate your application to Next.js but still need to fallback to an existing application. You can add pages to your Next.js application one-by-one and then for non-migrated pages Next.js can proxy to the existing application until they are able to be migrated.
......
import Link from "next/link"; import Link from "next/link";
import { useRouter } from "next/router";
export default function About() {
const router = useRouter();
export default function About({ params }: { params: { slug: string } }) {
return ( return (
<div> <div>
<h3>This is the `hello/[slug]` page. slug: {router.query.slug} </h3> <h3>This is the `hello/[slug]` page. slug: {params.slug} </h3>
<Link href="/">&larr; Back home</Link> <Link href="/">&larr; Back home</Link>
</div> </div>
); );
......
import type { Metadata } from "next";
export const metadata: Metadata = {
title: "Home",
description: "Welcome to Next.js",
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" /> /// <reference types="next/image-types/global" />
// NOTE: This file should not be edited // NOTE: This file should not be edited
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. // see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
}, },
"dependencies": { "dependencies": {
"next": "latest", "next": "latest",
"react": "^18.2.0", "react": "^18.3.1",
"react-dom": "^18.2.0" "react-dom": "^18.3.1"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^18.6.0", "@types/node": "^22.5.0",
"@types/react": "^18.0.15", "@types/react": "^18.3.4",
"@types/react-dom": "^18.0.6", "@types/react-dom": "^18.3.0",
"typescript": "^4.7.4" "typescript": "^5.5.4"
} }
} }
...@@ -13,8 +13,14 @@ ...@@ -13,8 +13,14 @@
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
"jsx": "preserve", "jsx": "preserve",
"incremental": true "incremental": true,
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
}, },
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"] "exclude": ["node_modules"]
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment