Skip to content

Commit be3514c

Browse files
committed
Use exact routes to pages
By default, react route matches a URI (let's say) greedy which means the following route: <Route path="/about" ... /> will match the following URIs: /about /about/ /about/foo /about/foo/bar Well, that's not what would we expect. That's why we want to set 'exact' option on routes, so only two cases would be allows for the example above: /about /about/ Any other options will end up with 404 Not Found.
1 parent f7d52c8 commit be3514c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/components/Main.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ const Main = () => (
1313
<main className="main">
1414
<Switch>
1515
<Route exact path="/" component={NewSnippet} />
16-
<Route path="/recent" component={RecentSnippets} />
17-
<Route path="/about" component={About} />
18-
<Route path="/sign-in" component={SignIn} />
19-
<Route path="/:id" component={Snippet} />
16+
<Route exact path="/recent" component={RecentSnippets} />
17+
<Route exact path="/about" component={About} />
18+
<Route exact path="/sign-in" component={SignIn} />
19+
<Route exact path="/:id(\d+)" component={Snippet} />
2020
</Switch>
2121
</main>
2222
);

0 commit comments

Comments
 (0)