Skip to content

Commit 0fe1894

Browse files
authored
Merge pull request #160 from xsnippet/fix-routing
Fix routing
2 parents a937493 + eaadef2 commit 0fe1894

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/components/App.jsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Fragment, useEffect, useState } from 'react'
2-
import { BrowserRouter as Router, Route } from 'react-router-dom'
2+
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
33

44
import Header from './Header'
55
import Sidebar from './Sidebar'
@@ -47,11 +47,15 @@ const App = () => {
4747
<div className="content">
4848
<Sidebar />
4949
<main className="main">
50-
<Route exact path="/" component={NewSnippet} />
51-
<Route exact path="/recent" component={RecentSnippets} />
52-
<Route exact path="/:id([a-zA-Z0-9]+)" component={Snippet} />
53-
<Route exact path="/about" component={About} />
54-
<Route exact path="/sign-in" component={SignIn} />
50+
<Switch>
51+
<Route exact path="/" component={NewSnippet} />
52+
<Route exact path="/about" component={About} />
53+
<Route exact path="/recent" component={RecentSnippets} />
54+
<Route exact path="/sign-in" component={SignIn} />
55+
// Switch renders the first matched route, so we need to keep this
56+
// one last as the regexp below matches the paths of other pages
57+
<Route exact path="/:id([a-zA-Z0-9]+)" component={Snippet} />
58+
</Switch>
5559
</main>
5660
</div>
5761
</Fragment>

0 commit comments

Comments
 (0)