Skip to content

Instantly share code, notes, and snippets.

View AnishDe12020's full-sized avatar
🚀
Buidling

Anish De AnishDe12020

🚀
Buidling
View GitHub Profile
npm install next@latest
yarn add next@latest
const middleware = (req, ev) => {
return new Response(req.ua.os.name);
};
export default middleware;
import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'
export default function Home() {
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
import {NextResponse} from "next/server"
const os = req.ua.os.name
return NextResponse.rewrite(`/${os}`) // This return is necessary
import {NextResponse} from "next/server"
const middleware = (req, ev) => {
const os = req.ua.os.name
return NextResponse.rewrite(`/${os}`)
};
export default middleware;
import {useRouter} from "next/router"
const router = useRouter()