Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react router next page top

import {Routes, Route, BrowserRouter as Router, useLocation} from 'react-router-dom';
import {useLayoutEffect} from 'react';

// funtion to set top to the next route page
const Wrapper = ({children}) => {
  const location = useLocation();
  useLayoutEffect(() => {
    document.documentElement.scrollTo(0, 0);
  }, [location.pathname]);
  return children
} 

//wrap the routes with wrapper component
<BrowserRouter>
  <Wrapper>
    <Navbar />
      <Routes>
        <Route exact path="/" element={<Home/>} />
        <Route path="/Products" element={<Products/>} />
        <Route path="/Login" element={<Login/>} />
        <Route path="/Aggressive" element={<Aggressive/>} />
        <Route path="/Attendance" element={<Attendance/>} />
        <Route path="/Choking" element={<Choking/>} />
        <Route path="/EmptyCounter" element={<EmptyCounter/>} />
        <Route path="/FaceMask" element={<FaceMask/>} />
        <Route path="/Fainting" element={<Fainting/>} />
        <Route path="/Smoking" element={<Smoking/>} />
        <Route path="/SocialDistancing" element={<SocialDistancing/>} />
        <Route path="/Weapon" element={<Weapon/>} />
      </Routes>
    <Footer />
  </Wrapper>
</BrowserRouter>
Comment

PREVIOUS NEXT
Code Example
Javascript :: code Execution time in nodejs 
Javascript :: hide and show modal in jquery 
Javascript :: set time to zero in js date 
Javascript :: How to install react native hooks with npm 
Javascript :: javascript remove empty object items 
Javascript :: xhr request 
Javascript :: js check window active 
Javascript :: how to run angular application in visual studio code 
Javascript :: refresh current component angular 
Javascript :: javascript transition 
Javascript :: refresh datatable on button click with maintaining paging 
Javascript :: javascript check for property 
Javascript :: content editable vuejs 
Javascript :: d3.json() function 
Javascript :: comparsion javascript 
Javascript :: angular event emitter 
Javascript :: javascript date get nearest 15 minutes 
Javascript :: react router multiple path 
Javascript :: history.push 
Javascript :: button size react native 
Javascript :: javascript parse a json string 
Javascript :: js generate random number 
Javascript :: if jsp 
Javascript :: mongodb import from json 
Javascript :: putting a loop into an array javascript 
Javascript :: install react native gifted charts 
Javascript :: find array with children javascript 
Javascript :: js round 2 digits 
Javascript :: get page link angular 
Javascript :: javascript sum of array 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =