I'm trying to make a news-feed website with React.js.
How to make a Router with the news ID? I'm trying something like this:
<Route path="/news/:id">
{ ( {id} ) => <NewsPiece newsID={id}/> }
</Route>
But it didn't work out. I tried to look it up but didn't find any way convenience.
Below is my App.js being the main file.
import React from 'react';
import NavBar from './components/NavBar'
import Container from './components/Container'
import NewsPiece from './components/NewsPiece'
import Topics from './components/Topics'
import {
BrowserRouter as Router,
Switch,
Route,
} from "react-router-dom";
function App() {
return (
<React.Fragment>
<NavBar/>
<Router>
<Switch>
<Route path="/news/:id">
{ ( {id} ) => <NewsPiece newsID={id}/> }
</Route>
<Route path="/news">
<Topics/>
</Route>
<Route path="/">
<Container/>
</Route>
</Switch>
</Router>
</React.Fragment>
);
}
export default App;