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) {
db.getOtherUser(req.params.id)
.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
<BrowserRouter>
<Nav>
</Nav>
<Switch>
///routes////
<Redirect from="/u/2" to="/" /> //test route I made, doesn't work
</Switch>
</BrowserRouter>
Set your routes in the React app something like this
Now if any route other than "mainpage" is entered it will be redirected to
/