Last night I run the same code it worked but today is not working anymore. the route is not working properly, ‘/’ route is working properly but ‘/search’ is not working. I didn’t change any of my code. why it’s happening?
JavaScript
x
15
15
1
<Router>
2
<Header />
3
<Switch>
4
<Route path='/'>
5
<div className='app__page'>
6
<Sidebar />
7
<RecommendedVideos />
8
</div>
9
</Route>
10
<Route path='/search:searchTerm'>
11
<h2>Search page</h2>
12
</Route>
13
</Switch>
14
</Router>
15
Advertisement
Answer
Fix your routes configuration:
JavaScript
1
15
15
1
<Router>
2
<Header />
3
<Switch>
4
<Route exact path='/'>
5
<div className='app__page'>
6
<Sidebar />
7
<RecommendedVideos />
8
</div>
9
</Route>
10
<Route path='/search/:searchTerm'>
11
<h2>Search page</h2>
12
</Route>
13
</Switch>
14
</Router>
15