I am working on React and Node
Now, I want to create a dynamic URL to show user profile
In Node with EJS we could have simply done something like this
route.get("/:id", function(req, res) {
playground.find({}, function (error, plyground) { //MongoDb find syntex
if (error) {
console.log(error);
} else {
playground.findById(req.params.id).populate("comments").exec(function(error, playground) {
if (error) {
console.log("error -> Show route or more information about playground")
}
else {
res.render("playground/show", {playground:playground, plyground:plyground})
}
});
}
})
})
Here since EJS and Node both work on the same address, hence whenever user reaches /:id it would find the user info from the DB and render it.
In case of react, my node application is running on localhost:8080 and react app on localhost:3000
I am interacting by either making API calls using axios or redirecting to react webpage address.
Now, I want to show user profile in React when someone reaches
route.get("/:id", function(req, res) {
Question: So can someone please tell me how will I be able to create dynamic URL react app?
Ps: I am using react-route for navigating in my react app
import React from 'react';
import { BrowserRouter, Route, Switch } from 'react-router-dom'
//Remaining imports
const route = () => {
return(
<BrowserRouter>
<div>
<Switch>
<Route path ="/" exact render ={(props) => <Home {...props}/>} />
<Route path ="/signup" exact render ={(props) => <Signup {...props}/>} />
<Route path ="/Home" exact render={(props) => <MainHomeScreen {...props}/>} />
</Switch>
</div>
</BrowserRouter>
)
}
export default route;