Skip to content

Instantly share code, notes, and snippets.

@react-ram
Created May 1, 2020 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save react-ram/e691f3b3d3df180e999158432100caf4 to your computer and use it in GitHub Desktop.
Save react-ram/e691f3b3d3df180e999158432100caf4 to your computer and use it in GitHub Desktop.
Basic React Router DOM Example - 1
import React from "react";
import "./App.css";
import { BrowserRouter as Router, Route, Switch, Link } from "react-router-dom";
function LandingView() {
return <div>LandingView</div>;
}
function Login() {
return (
<div>
Loginview
<p>
<Link to="/">back</Link>
</p>
</div>
);
}
function Register() {
return (
<div>
Register view
<p>
<Link to="/">back</Link>
</p>
</div>
);
}
function App() {
return (
<Router>
<div className="App">
<div>
appbar{" "}
<p>
<Link to="/login">Login</Link>
</p>
<p>
<Link to="/register">Register</Link>
</p>
</div>
<div>
<Switch>
<Route path="/" exact>
<LandingView />
</Route>
<Route path="/login">
<Login />
</Route>
<Route path="/register">
<Register />
</Route>
</Switch>
</div>
</div>
</Router>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment