Unverified Commit e32a4c85 authored by Max Proske's avatar Max Proske Committed by GitHub

Convert `custom-routes-proxying` example to TypeScript (#38974)

Converted `custom-routes-proxying` example to TypeScript to match Contribution docs.

## Documentation / Examples

- [X] Make sure the linting passes by running `pnpm lint`
- [X] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent 07c3464a
...@@ -32,3 +32,6 @@ yarn-error.log* ...@@ -32,3 +32,6 @@ yarn-error.log*
# vercel # vercel
.vercel .vercel
# typescript
*.tsbuildinfo
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
module.exports = { // @ts-check
/**
* @type {import('next').NextConfig}
**/
const nextConfig = {
async rewrites() { async rewrites() {
return { return {
fallback: [ fallback: [
...@@ -10,3 +15,5 @@ module.exports = { ...@@ -10,3 +15,5 @@ module.exports = {
} }
}, },
} }
module.exports = nextConfig
...@@ -7,7 +7,13 @@ ...@@ -7,7 +7,13 @@
}, },
"dependencies": { "dependencies": {
"next": "latest", "next": "latest",
"react": "^17.0.2", "react": "^18.2.0",
"react-dom": "^17.0.2" "react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^18.6.0",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"typescript": "^4.7.4"
} }
} }
import Link from 'next/link' import Link from 'next/link'
export default function About() { export default function About() {
return ( return (
<div> <div>
<h3>This is the /about page. </h3> <h3>This is the /about page. </h3>
<Link href="/"> <Link href="/">&larr; Back home</Link>
<a> &larr; Back home</a>
</Link>
</div> </div>
) )
} }
...@@ -2,12 +2,12 @@ import Link from 'next/link' ...@@ -2,12 +2,12 @@ import Link from 'next/link'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
export default function About() { export default function About() {
const router = useRouter()
return ( return (
<div> <div>
<h3>This is the `hello/[slug]` page. slug: {useRouter().query.slug}</h3> <h3>This is the `hello/[slug]` page. slug: {router.query.slug} </h3>
<Link href="/"> <Link href="/">&larr; Back home</Link>
<a> &larr; Back home</a>
</Link>
</div> </div>
) )
} }
import Link from 'next/link' import Link from 'next/link'
export default function Home() { export default function Home() {
return ( return (
<div> <div>
<h3>Hello World.</h3> <h3>Hello World.</h3>
<Link href="/about"> <Link href="/about">About</Link>
<a>About</a>
</Link>
<br /> <br />
<Link href="/hello/[slug]" as="/hello/world"> <Link href="/hello/[slug]" as="/hello/world">
<a>Hello world</a> Hello world
</Link> </Link>
</div> </div>
) )
......
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"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