code is not working properly while it worked very well last night with same [closed]



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?

<Router>
        <Header />
        <Switch>
          <Route path='/'>
            <div className='app__page'>
              <Sidebar />
              <RecommendedVideos />
            </div>
          </Route>
          <Route path='/search:searchTerm'>
            <h2>Search page</h2>
          </Route>
        </Switch>
</Router>

Answer

Fix your routes configuration:

<Router>
   <Header />
   <Switch>
     <Route exact path='/'>
       <div className='app__page'>
         <Sidebar />
         <RecommendedVideos />
       </div>
     </Route>
     <Route path='/search/:searchTerm'>
       <h2>Search page</h2>
     </Route>
   </Switch>
</Router>


Source: stackoverflow