Skip to content

Commit

Permalink
Changed the routes to new route syntax from old component syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
sridhar02 committed Jun 11, 2020
1 parent 96d576c commit 9889e2e
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
import React from "react";
import ReactDOM from "react-dom";
import { Route, BrowserRouter as Router, Switch } from "react-router-dom";
import {
Route,
BrowserRouter as Router,
Switch,
useLocation,
} from "react-router-dom";

import Stories from "./components/stories";
import Story from "./components/story";
import CreateStory from "./components/createStory";
import Login from "./components/login";

function NoMatch() {
let location = useLocation();

return (
<div>
<h3>
No match for <code>{location.pathname}</code>
</h3>
</div>
);
}

function Main() {
return (
<Router>
<Switch>
<Route path="/" component={Login} exact />
<Route path="/stories" component={Stories} exact />
<Route path="/story/new" component={CreateStory} exact />
<Route path="/story/:id" component={Story} exact />
<Route exact path="/">
<Login />
</Route>
<Route path="/stories">
<Stories />
</Route>
<Route path="/story/new">
<CreateStory />
</Route>
<Route path="/story/:id">
<Story />
</Route>
<Route path="*">
<NoMatch />
</Route>
</Switch>
</Router>
);
Expand Down

0 comments on commit 9889e2e

Please sign in to comment.