Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

active nav links in next.js

import Link from "next/link";
import { useRouter } from "next/router";


export const MyNav = () => {

  const router = useRouter();

  return (
    <ul>
      <li className={router.pathname == "/" ? "active" : ""}>
        <Link href="/">home</Link>
      </li>
      <li className={router.pathname == "/about" ? "active" : ""}>
        <Link href="/about">about</Link>
      </li>
    </ul>
  );
};

Comment

next js active nav link

import Link from "next/link";
import { useRouter } from "next/router";


export const MyNav = () => {

  const router = useRouter();

  return (
    <ul>
      <li className={router.asPath == "/#about" ? "active" : ""}>
        <Link href="#about">about</Link>
      </li>
    </ul>
  );
}`;
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to update the react version in next js app 
Javascript :: js page auto reload 
Javascript :: javascript stop the form from reloading 
Javascript :: number to word js 
Javascript :: change index array javascript 
Javascript :: react native modal not full screen 
Javascript :: json-server npm 
Javascript :: javascript reduce fraction 
Javascript :: javascript input prompt example 
Javascript :: lazy react 
Javascript :: js php number format 
Javascript :: delete local storage javascript 
Javascript :: how to push string into array in javascript 
Javascript :: js select by data attribute 
Javascript :: inner html jquery 
Javascript :: mongoose find sort 
Javascript :: react-router-dom redirect 
Javascript :: js check if string includes from array 
Javascript :: union of two arrays javascript 
Javascript :: joi custom error 
Javascript :: javascript get all characters before a certain one 
Javascript :: Regular Expression for Detect Iranian Mobile Phone Numbers | IR mobile number Regex Pattern 
Javascript :: preventdefault not working react 
Javascript :: angular x social login 
Javascript :: store data to the browser’s localStorage 
Javascript :: install latest electron 
Javascript :: nuxt emit 
Javascript :: javascript reverse string 
Javascript :: detect resize window javascript 
Javascript :: math round 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =