Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

History push for redirecting to another page in react-router v6

import React from 'react';

const LocationContext = React.createContext();

export default function Router({ children }) {
  return (
    <LocationContext.Provider
      value={{
        // The current location
        location: window.location,
        navigator: {
          // Change url and push entry in the history
          push(to) {
            window.history.pushState(null, null, to);
          },
          // Change url and replace the last entry in the history
          replace(to) {
            window.history.replaceState(null, null, to);
          },
          // Go back to the previous entry in the history
          back() {
            window.history.go(-1);
          },
          // Go forward to the next entry in the history
          forward() {
            window.history.go(1);
          },
          // If we want to go forward or 
          // backward from more than 1 step
          go(step) {
            window.history.go(step);
          }
        }
      }}
    >
      {children}
    </LocationContext.Provider>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Movie-app using react 
Javascript :: filtering jquery 
Javascript :: UnhandledPromiseRejectionWarning 
Javascript :: js insert 
Javascript :: window frames js 
Javascript :: run function after another function javascript 
Javascript :: usereduce 
Javascript :: remove first character javascript 
Javascript :: boolean as string javascript 
Javascript :: pass function with parameter as prop 
Javascript :: modal multiple images 
Javascript :: javascript array slice() example 
Javascript :: update property of object in array javascript 
Javascript :: npm module 
Javascript :: Do not use forEach with async-await 
Javascript :: vanilla tilt js 
Javascript :: js try without catch 
Javascript :: js detect end of array 
Javascript :: javascript create array 
Javascript :: java script alerts 
Javascript :: laravel json eloquent 
Javascript :: how to remove the last value of javascript array 
Javascript :: pass props from child to parent 
Javascript :: slot vuetify js 
Javascript :: how to make callback function javascript 
Javascript :: copy to clipboard jquery 
Javascript :: break loop if condition is met 
Javascript :: javascript ajax post send an object 
Javascript :: useref initial value 
Javascript :: regex or operator 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =