Comments (4)
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.
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.
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.
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}
);
}
- 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.
- 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.
- 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.
- Predictable Behavior: The proposed code ensures a predictable behavior for opening new tabs, addressing the issue of URLs not reloading correctly.
- 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)
- Bug: Clean up useEffect given [] empty dependency array causes a tedious linter error HOT 11
- Bug: eslint-plugin-react-hooks: Incorrect dependency requirement when using `typeof` on nested data structures HOT 7
- React Dev Tools doesn't work HOT 18
- ADD Suppport for VEDV (https://github.com/yunielrc/vedv)
- Bug: `srcSet` prop is rendered to `srcSet` attribute (instead of `srcset`) HOT 6
- ใ ใดใ ใน
- Control blocking vs lazy behavior of Suspense during renderToPipeableStream HOT 7
- Bug: Can't use bigint for the key property HOT 15
- how to use react developer tools in chrome HOT 1
- [Feature Request]: RSC error - allow error.code or an other specialized prop to be forwarded to the client HOT 1
- Bug: Components which doesn't consume Context are re-rendered when context state is updated HOT 1
- Bug: HOT 1
- Bug: react-dom/server.bun in `@canary` hangs without flushing or terminating the connection on long class names(?) HOT 3
- Bug: react-test-renderer types of .toTree API are missing HOT 4
- Bug: missing button data in form when submitted via `formAction` HOT 11
- Is react abandoned? HOT 7
- Bug: Suspense does not work in Server Components with `use` api
- Regarding component splitting in react... HOT 5
- Bug: react native android shaking on scroll HOT 1
- Bug: renderToString and renderToStaticMarkup skipping children for HTML custom elements HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react.