On a react project created with create-react-app, if your start your project, it starts the browser with the default http://localhost:3000
URL. That may be convenient in many cases, but in some projects you want it to call up a parameterized default route instead.
As trivial as that sounds, it does take a few steps and a dependency to achieve. :ogre:
-
install open-cli as a dev dependency `yarn add -d open-cli"
-
edit or create a
.env
file in your react folder. -
add this entry to it:
BROWSER=open.js
-
create this file
open.js
in your react folder and add the following content into it:
const open = require('open');
(async () => {
await open('http://localhost:3000/#my-start-view/something/123456')
})()
If you run your script now, it should open the browser to the specified URL instad of just to localhost.