When starting your react project, make it open the browser with a URL including parameters

martin friedel

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:

  1. install open-cli as a dev dependency `yarn add -d open-cli"

  2. edit or create a .env file in your react folder.

  3. add this entry to it: BROWSER=open.js

  4. 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.