InterviewSolution
Saved Bookmarks
| 1. |
How react router works |
|
Answer» React router is a commonly USED module for routing in React applications. React router COMPONENT listens to history changes in React applications. It has a URL mapping to components in it. It renders the corresponding component when a MATCH is found. Link component is used to NAVIGATE around in your application. Code sample below import React from "react"; import ReactDOM from "react-dom"; import "./styles.css"; import { BrowserRouter as Router, Route, Link } from "react-router-dom"; const App = () => ( <Router> <> <Link to="/">Home</Link> <Link to="/page">Page</Link> <Route exact path="/" component={Home} /> <Route path="/page" component={Page} /> </> </Router> ) const Home = () => <H2>Home</h2>; const Page = () => <h2>Page</h2>; const rootElement = document.getElementById("root"); ReactDOM.render(<App label="Save" />, rootElement); |
|