declaring react routes in a separate file and importing
import { BrowserRouter as Router, Route, Link, Switch, useParams } from "react-router-dom";
export default function App() {
const name = 'John Doe'
return (
<Router>
<main>
<nav>
<ul>
<li><Link to="/">Home</Link></li>
<li><Link to={`/about/${name}`}>About</Link></li>
</ul>
</nav>
<Switch>
<Route path="/" exact component={Home} />
<Route path="/about/:name" component={About} />
</Switch>
</main>
</Router>
);
}
const About = () => {
const { name } = useParams()
return (
// props.match.params.name
<Fragment>
{ name !== 'John Doe' ? <Redirect to="/" /> : null }
<h1>About {name}</h1>
<Route component={Contact} />
</Fragment>
)
};
Also in JavaScript:
- number of edges between set of nodes networkx
- calculate width of text javascript
- new date() javascript
- referenceerror document is not defined node js
- express cookies
- javascript true string to boolean
- u017f javascript
- remarkable react js
- sum array without loop javascript
- cannot find name json angular 7
- node js require file in parent directory
- switch alert
- disable javascript chrome
- array dia semana javascript
- usestate() react
- javascript bubble sort
- ant design react
- boucle for javascript
- Discord embeds
- how to use cordova screen shot
- js keyboard input
- error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.40/images/json:
- ERROR TypeError: Cannot assign to read only property 'reportAirport' of object '[object Object]
- check if a class exists javascript