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

141
Vistas
Open a link in new tab when a condition is true in React

There is a Tab component with multiple tabs, it is needed that when one of those tabs is clicked to open a link in a new tab in browser.

This is the code:

import { LocationDescriptor } from 'history';
import React, { AnchorHTMLAttributes } from 'react';
import { NavLink } from 'react-router-dom';

export interface ITabLinkItem extends AnchorHTMLAttributes<HTMLAnchorElement> {
  link: LocationDescriptor;
  name: string;
  disabled?: boolean;
}

export interface TabLinkProps {
  tabs: Array<ITabLinkItem>;
}

export function TabsLink({ tabs }: TabLinkProps) {
  const preventClick = (event: React.MouseEvent, disabled = false) => {
    disabled && event.preventDefault();
  };

  const clickTab = (event: React.MouseEvent, tab: ITabLinkItem) => {
    preventClick(event, tab.disabled);
    const { link } = tab;

    if (link === '/test') {
      // OPEN IN NEW TAB
    }
  };
  return (
    <div>
      {tabs.map((tab: ITabLinkItem, index: number) =>
        <NavLink
          key={index}
          to={tab.link}
          onClick={(event: React.MouseEvent) => clickTab(event, tab)}
        >
          {tab.name}
        </NavLink>
      )}
    </div>
  );
}

export default TabsLink;

Is it a way to trigger that tab opening when the condition is true?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You cannot maintain state in a new tab (so you will have to use cookies/localstate or some nifty database connections etc if you want that). So if this is the case and the new tab may be 'dumb' then why not use an a link with a target='_blank'.

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