title: How to make a get request using URL in React?
body: <p>I am using React as my front end and express for backend.</p>
  <p>As far as I know if I declare get methods in my express as follows:-</p>
  <pre><code>app.get('/addBill',(req,res)=&gt;{     //  --first method
      res.render(&quot;addBill&quot;);  
  });
  
  app.get('/edit/:id', (req, res) =&gt; {  // --second method
      res.render(&quot;EditBill&quot;); 
  });
  </code></pre>
  <p>If I write something like <strong>localhost:3000/addBill</strong> in the URL then I end up hitting <strong>first method</strong>, and if I write <strong>localhost:3000/edit/1</strong> in the URL then I end up hitting <strong>second method</strong> and get the required page if I am not using React and using it with <strong>ejs</strong>. Is the same possible in React?</p>
  <p>What I want to do in React is if I write in my URL <strong>localhost:3000/addBill</strong> then I get to <strong>/addBill</strong> method and if I write <strong>localhost:3000/edit/1</strong> then I get to <strong>/editBill</strong> method and perform some action depending on the method I reached.</p>
  <p>I am unable to use the URL for this and the only way I can do it right now is using fetch API, which allows for only one call independent of whatever is in URL. I am making a call like below:-</p>
  <pre><code>function App() {
    const [data, setData] = useState(null);
  
    useEffect(() =&gt; {
      fetch(&quot;/add&quot;)//---- or using edit in place of add,basically how to make this call dynamic and/or URL dependent?
        .then((res) =&gt; res.json())
        .then((data) =&gt; setData(data.message));
    }, []);
    return (
      &lt;div className=&quot;App&quot;&gt;
      &lt;p&gt;{!data ? &quot;Loading...&quot;: data}&lt;/p&gt;
        &lt;BillTable /&gt;
      &lt;/div&gt;
      
    );
  }
  </code></pre>
  <p>What changes are needed and where to allow me to make calls depending upon what I write in the URL?</p>