History.push a link to a new tab with react router

React-router’s history is meant to be used just for the navigation of your application and some persistance. I can’t see why you need to use it to open a new tab. I think you should use the window object for this. const handleSubmit = () => { console.log(“doing something”); const win = window.open(“/some-link”, “_blank”); win.focus(); … Read more

Navigating Programmatically in React-Router v4

The router will add a history object to your component in the props hash. So in your component, simply do: this.props.history.push(‘/mypath’) Here is a full example: In App.js: import React from ‘react’ import {BrowserRouter as Router, Route} from ‘react-router-dom’ import Login from ‘./Login’ export default class App extends React.Component { render() { return ( <Router> … Read more

Alternate way for optional parameters in v6

[email protected]+ Optional segments/parameters have been re-introduced to the library. The docs have been updated, but v6.5.0 Release Notes include the details as well. The above routes can be merged to a single route: <Route path=”/cart/:id?” element={<CartPage />} /> [email protected] After quite a bit of digging through the source code to understand how path parsing was … Read more