Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Routes in react-router-dom@6 and take the path by useLocation() hook

function App() {
  const location = useLocation();
  const [activePlanet, setActivePlanet] = useState('/');

  return (
    <Routes location={location}>
      <Route
        path="/"
        element={
          <DefaultLayout pathName={location.pathname} setActivePlanet={setActivePlanet} activePlanet={activePlanet} />
        }>
        <Route index element={<Home activePlanet={activePlanet} />} />
        {routes.map((route, idx) => (
          <Route key={`route-${idx}`} path={route.path} element={route.element} />
        ))}
      </Route>
    </Routes>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript slice string from character 
Javascript :: react native tab navigation header 
Javascript :: jquery date format 
Javascript :: foreach method of array in javascript 
Javascript :: js loop through function arguments 
Javascript :: promise in javascript 
Javascript :: react js error boundary functional component 
Javascript :: check if div contains background image 
Javascript :: template literals javascript 
Javascript :: java script alert 
Javascript :: switch react router 
Javascript :: setinterval vs settimeout 
Javascript :: how to check if the number inputed is number 
Javascript :: jQ - on image load 
Javascript :: react native lottie 
Javascript :: delete element from array js 
Javascript :: mongoose remove data 
Javascript :: get list of text from div in js 
Javascript :: variables in js 
Javascript :: Content security policy (csp) javascript 
Javascript :: tailwind container class size 
Javascript :: get selected option text jquery 
Javascript :: javascript Program with a Promise 
Javascript :: how to set value of tinymce in javascript 
Javascript :: search string javascript 
Javascript :: elapsed time function() {math javascript 
Javascript :: wavesurf js 
Javascript :: angular httpclient post body 
Javascript :: import npm module node.js 
Javascript :: momentjs get calendar week 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =