Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

usenavigate

In react-router-dom version 6 
useHistory() is replaced by useNavigate() ;

import {useNavigate} from 'react-router-dom';
const navigate = useNavigate();
navigate('/home')
Comment

useNavigate

// React Router v6
import { useNavigate } from 'react-router-dom';

export function GoHome() {
  let navigate = useNavigate();
  const handleClick = e => {
    e.preventDefault();
    navigate('/home');
  }
  return <button onClick={handleClick}>Go to Home</button>
}
Comment

useNavigate

<Navigate to="/dashboard" replace={true} />
Comment

useNavigate in react

import { useNavigate } from "react-router-dom";

const navigate = useNavigate();

const submitHandler = async (event) => {
  event.preventDefault();

  try {
    await submitForm();
    navigate("/success"); // Omit optional second argument
  } catch (error) {
    navigate("/error", { state: { message: "Failed to submit form" } }); // Pass optional second argument
  }
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: mac install jmeter 
Javascript :: how to ask input in javascript 
Javascript :: detect keypress 
Javascript :: parse integer javascript 
Javascript :: create stack navigator has been moved to react-navigation-stack 
Javascript :: pattern telefone js 
Javascript :: Datatables Text Align Center 1 Or More Column 
Javascript :: get guild by id discord.js 
Javascript :: node js random number generator 
Javascript :: js number add zero before 
Javascript :: create an array of numbers by numbers range in angular 
Javascript :: angular material change placeholder color 
Javascript :: query params vuejs 
Javascript :: how to check connected devices in react native 
Javascript :: fs in angular 
Javascript :: js get last 4 digits 
Javascript :: react native loading 
Javascript :: usehistory not found in react-router-dom 
Javascript :: javascript trim each element in array 
Javascript :: javascript download json 
Javascript :: moment locale 
Javascript :: javascript get all select options 
Javascript :: sort ip address javascript 
Javascript :: node express post request json 
Javascript :: how to output only a certain length of a string in javascript 
Javascript :: get h1 text javascript 
Javascript :: generate random random number with fixed length 
Javascript :: end code nodejs 
Javascript :: fetch json 
Javascript :: communication with service worker 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =