Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

next js active link

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

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 :: hook access loopback 
Javascript :: var data ="<tr<td"+ data.data[i].name"</td"+"<td"+ data.data[i].email"</td"+"<td"+ data.data[i].create_at"</td</tr"; 
Javascript :: change background image through props 
Javascript :: javascript persistent storage 
Javascript :: get value by id js 
Javascript :: check if url contains string 
Javascript :: fs move file 
Javascript :: add element to array using splice 
Javascript :: axios pass params 
Javascript :: comparing two lists in javascript 
Javascript :: return longest string from array 
Javascript :: A form label must be associated with a control react 
Javascript :: js format urcurency 
Javascript :: map images from folder react 
Javascript :: javascript redirect function 
Javascript :: display none javascript 
Javascript :: while loop countdown javascript 
Javascript :: Javascript looping through table 
Javascript :: check if string contains word nodejs 
Javascript :: how to wait in javascript 
Javascript :: get random letter js 
Javascript :: random array javascript 
Javascript :: javascript returned function and copy to clipboard 
Javascript :: get column from 2D array javascript 
Javascript :: javascript map 2 array of objects 
Javascript :: settimeout 
Javascript :: (node:2496) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead. 
Javascript :: ajax authorization header token 
Javascript :: how to get clicked element class in jquery 
Javascript :: how to add parameters to url javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =