GithubHelp home page GithubHelp logo

Comments (4)

vimal20002 avatar vimal20002 commented on May 3, 2024 2

I think you should use react-router-dom for routing you want to open something in new tab giving it dynamic url you can do like this

const uri = /#/issues/" + props.data.issueNumber;
<Link target={"_blank"} to={uri} > {"#issue"+props.data.issueNumber } </Link>
and add a route tag with dynamic tag

<Route exact path ="/issues/:id"><Issue/></Route>
and in Issue component you can do filter using id that you can get from useParams and display the data accordingly
I tried it will provide expected behavior as you want

from react.

iamabhshk avatar iamabhshk commented on May 3, 2024
import { ICellRendererParams } from "ag-grid-community";
import { Link } from "react-router-dom";

export default function IssueDetailCellRenderer(props: ICellRendererParams) {
  return (
    <Link
      to={"/issues/" + props.data.issueNumber}
      target="_blank"
      rel="noopener noreferrer"
      style={{ textDecoration: "none" }}
    >
      {props.value}
    </Link>
  );
}

This might help

from react.

ApoorvSeth avatar ApoorvSeth commented on May 3, 2024

const uri = /#/issues/" + props.data.issueNumber;

Query is not "How to open a new tab"

My Issue is after opening a new tab(loaded successfully), when I am trying to change URL of this tab directly and press Enter. Brower does not reload. Only if I click on URL tab again and press Enter again it reload.

from react.

Swapnilchavan13 avatar Swapnilchavan13 commented on May 3, 2024

import { ICellRendererParams } from "ag-grid-community";
import { useEffect } from "react";

export default function IssueDetailCellRenderer(props: ICellRendererParams) {
useEffect(() => {
function handleLinkClick(event) {
event.preventDefault();
const newTab = window.open("", "_blank");
if (newTab) {
newTab.location.href = "/#/issues/" + props.data.issueNumber;
}
}

const linkElement = document.getElementById(`issue-link-${props.rowIndex}`);
if (linkElement) {
  linkElement.addEventListener("click", handleLinkClick);
}

return () => {
  if (linkElement) {
    linkElement.removeEventListener("click", handleLinkClick);
  }
};

}, [props.data.issueNumber, props.rowIndex]);

return (
<a
sx={{ textDecoration: "none" }}
href="/#/issues/"
id={issue-link-${props.rowIndex}}
>
{props.value}

);
}

  1. Page Reloading Issue: The current implementation using may cause page reloading problems when you directly change the URL in the new tab and press Enter. Using an anchor tag with JavaScript provides better cross-browser compatibility compared to the custom MUI component behavior.
  2. URL Manipulation: Handling the link click event with JavaScript allows more flexibility in URL manipulation and additional pre-navigation actions. Utilizing the useEffect hook ensures proper attachment and detachment of the event listener, avoiding memory leaks or conflicts.
  3. Control Over New Tab: window.open() and location.href offer more control over new tab behavior, like dimensions, location, and navigation to the desired URL.
  4. Predictable Behavior: The proposed code ensures a predictable behavior for opening new tabs, addressing the issue of URLs not reloading correctly.
  5. Scalability: By using standard anchor tags, the code can be easily maintained and scaled, reducing dependencies on specific UI libraries.

from react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.