Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get cuurent route name nextjs

import React from 'react'
import Link from 'next/link'
import { useRouter } from 'next/router'

const menu = [
  { title: 'Home', path: '/home' },
  { title: 'Explore', path: '/explore' },
  { title: 'Notifications', path: '/notifications' },
]

const Sidebar = () => {
  const router = useRouter()

  return (
    <div>
      {menu.map((item, index) => {
        return (
          <Link key={index} href={item.path}>
            <a
              className={`cursor-pointer ${
                router.pathname === item.path
                  ? 'text-blue-500'
                  : 'hover:bg-gray-900 hover:text-blue-500'
              }`}
            >
              {item.title}
            </a>
          </Link>
        )
      })}
    </div>
  )
}

export default Sidebar
Comment

PREVIOUS NEXT
Code Example
Javascript :: js add click listener 
Javascript :: how to get file extension in javascript last index 
Javascript :: disable all buttons jquery 
Javascript :: how to set header in angular 8post 
Javascript :: Required a safe HTML, got a ResourceURL 
Javascript :: larger text console javascript 
Javascript :: javascript remove element from array 
Javascript :: ubuntu nodejs update 
Javascript :: select only jpg jpeg images 
Javascript :: javascript check if first of type 
Javascript :: vs code prevent auto grml closing in js files 
Javascript :: react native cannot make request on localhost 
Javascript :: why request body is empty when using fetch 
Javascript :: react conditional classname 
Javascript :: copy text to clipboard jquery 
Javascript :: MongoServerSelectionError: connect ECONNREFUSED ::1:27017 
Javascript :: how to get the sum of a column in sequelize 
Javascript :: gradle json simple dependency 
Javascript :: js add delay 
Javascript :: js class method called when page loads 
Javascript :: remove undefined from array javascript 
Javascript :: this.$set 
Javascript :: speed facebook video 
Javascript :: checkbox is checked jquery 
Javascript :: how to change country code to country name in javascript 
Javascript :: cannot find module loader 936 
Javascript :: javascript remove empty elements from array 
Javascript :: jquery get top position of element on scroll 
Javascript :: jquery get date from datepicker 
Javascript :: stuck at "resolving packages" 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =