I have a react app that I am using express to handle db queries and the like, when I enter the express routes to get data say for a user:

    app.get("/u/:id", function(req, res) {
            .then(data => {
                res.json({ data });
            .catch(err => {
                console.log("OTHER USER ERROR", err);

I am still able to access the json data by manually entering it into the URL?

I have a created a to test its functionaity inside a switch but because it does receive data on that route it gets it at first

//in app.js




<Redirect from="/u/2" to="/" /> //test route I made, doesn't work



1 Answers

Gaurav_soni On

Set your routes in the React app something like this

   <Route path="/mainpage" exact component={MainPage} />
   <Redirect to="/" />

Now if any route other than "mainpage" is entered it will be redirected to /