Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
How can I change header color in different pages

this solution works but I have more than one location. how can I add red color into different locations.

import { useRouter } from "next/router";
function Header() {
  const router = useRouter();
  return (
    <>
      <ul>
         <li style={{ color : router.route == "/browse" ? "red" : "black" }}>Resut</li>
      </ul>
    </>
  )
}
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Keep a static collection of red routes and use that in your check. For example

// route-styles.js
export const RED_ROUTES = new Set([
  "/browse",
  "/some-other-route",
  // etc
]);
// Header.jsx
import { useRouter } from "next/router";
import { RED_ROUTES } from "./route-styles";

function Header() {
  const router = useRouter();
  return (
    <ul>
      <li
        style={{
          color : RED_ROUTES.has(router.route) ? "red" : "black" 
        }}
      >Resut</li>
    </ul>
  );
}

Another option might be to create a map of routes to colour. That would let you use more than just the two choices

// route-styles.js
export const COLORS = {
  "/browse": "red",
  "/some-other-route": "red",
  "/the-blue-one": "blue"
};

and in your component...

<li
  style={{
    color: COLORS[router.route] ?? "black"
  }}
>
about 4 years ago · Juan Pablo Isaza Denunciar

0

Maybe a array would work?

import { useRouter } from "next/router";
import styled from "styled-components";

function Header() {
  const router = useRouter();
  const theRoutes = ["home", "browser", "view", "about"]
  return (
    <>
      <ul>
        {theRoutes.map(route =>
          <li style={{ color: router.route === route ? "red" : "black" key={route}>{route}</li>
        )}
      </ul>
    </>
  )
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You could pass a prop to Header from page

export function Page () {
   return (
         <MainPage>
            // if you have BaseLayout you have to pass it to Baselayout and from there to Header
            // addiing only `red` prop will be evaluated red=True
            <Header red />

         <MainPage/>
   )
}

In your Header

     <li style={{ color : props.red ? "red" : "black" }}>Resut</li>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda