Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda