Skip to content

Commit

Permalink
Convert custom-routes-proxying example to TypeScript (#38974)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
maxproske committed Jul 25, 2022
1 parent 07c3464 commit e32a4c8
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 23 deletions.
3 changes: 3 additions & 0 deletions examples/custom-routes-proxying/.gitignore
Expand Up @@ -32,3 +32,6 @@ yarn-error.log*

# vercel
.vercel

# typescript
*.tsbuildinfo
5 changes: 5 additions & 0 deletions examples/custom-routes-proxying/next-env.d.ts
@@ -0,0 +1,5 @@
/// <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.
9 changes: 8 additions & 1 deletion examples/custom-routes-proxying/next.config.js
@@ -1,4 +1,9 @@
module.exports = {
// @ts-check

/**
* @type {import('next').NextConfig}
**/
const nextConfig = {
async rewrites() {
return {
fallback: [
Expand All @@ -10,3 +15,5 @@ module.exports = {
}
},
}

module.exports = nextConfig
10 changes: 8 additions & 2 deletions examples/custom-routes-proxying/package.json
Expand Up @@ -7,7 +7,13 @@
},
"dependencies": {
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.2.0",
"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"
}
}
@@ -1,11 +1,10 @@
import Link from 'next/link'

export default function About() {
return (
<div>
<h3>This is the /about page. </h3>
<Link href="/">
<a> &larr; Back home</a>
</Link>
<Link href="/">&larr; Back home</Link>
</div>
)
}
13 changes: 0 additions & 13 deletions examples/custom-routes-proxying/pages/hello/[slug].js

This file was deleted.

13 changes: 13 additions & 0 deletions examples/custom-routes-proxying/pages/hello/[slug].tsx
@@ -0,0 +1,13 @@
import Link from 'next/link'
import { useRouter } from 'next/router'

export default function About() {
const router = useRouter()

return (
<div>
<h3>This is the `hello/[slug]` page. slug: {router.query.slug} </h3>
<Link href="/">&larr; Back home</Link>
</div>
)
}
@@ -1,14 +1,13 @@
import Link from 'next/link'

export default function Home() {
return (
<div>
<h3>Hello World.</h3>
<Link href="/about">
<a>About</a>
</Link>
<Link href="/about">About</Link>
<br />
<Link href="/hello/[slug]" as="/hello/world">
<a>Hello world</a>
Hello world
</Link>
</div>
)
Expand Down
20 changes: 20 additions & 0 deletions examples/custom-routes-proxying/tsconfig.json
@@ -0,0 +1,20 @@
{
"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"]
}

0 comments on commit e32a4c8

Please sign in to comment.