Skip to content

somnas/webb20-js-lesson-3-routing

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Router Dom

npm install react-router-dom

  1. Import BrowserRouter to index.js

import {BrowserRouter} from 'react-router-dom'

ReactDOM.render(
  <React.StrictMode>
    <BrowserRouter>
      <App />
    </BrowserRouter>
  </React.StrictMode>,
  document.getElementById('root')
);
  1. Import Switch and Route to App.js

import { Switch, Route } from 'react-router-dom'

  1. Create Routes
<Switch>
    <Route path="/about">
        About me
    </Route>
    <Route path="/">
        Start Page
    </Route>
</Switch>
  1. Import Link

import { Switch, Route, Link } from 'react-router-dom'

  1. Create links to navigate between routes
<ul>
    <li>
        <Link to="/">Hem</Link>
    </li>
    <li>
        <Link to="/about">Om</Link>
    </li>
</ul>

```

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 51.3%
  • HTML 31.6%
  • CSS 17.1%