Reputation: 1225
I am using ag-grid and it has an event onSelectionChanged
, which make the row clickable. When I click on row below function is called.
const onSelectionChanged = useCallback(() => {
const selectedRow = gridRef.current.api.getSelectedRows(); //get the row data
let navigate = useNavigate(); //import { useNavigate } from "react-router-dom";
navigate('/Detail', { state: { data: selectedRow[0]} }); //navigate to detail page
}, []);
The function navigates to the detail page and the state is passed. But navigate()
calls the Detail
page in same tab.
I want to open the page in new tab. Is this possible using this method? or there is another way to accomplish my goal?
Upvotes: 2
Views: 5242
Reputation: 500
react-router
isn't supposed to help preserve state when opening things in a new tab. In fact, fundamentally, react
isn't supposed to help do this.
I'd approach this in two ways:
windows.open(window.open("http://link?key="+ value +"&key2="+ value2 ..."); )
localstorage
or something elseUpvotes: 3