Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to pass data between routes in react

// React Router v6
// pass data between routes
// ---------------------------------------------------------------------
// sender.js/jsx
import { useNavigate } from "react-router-dom";

const navigate = useNavigate();
navigate('/other-page', { state: { username: 'user', password: '696' } });
// ---------------------------------------------------------------------
// receiver.js/jsx
import { useLocation } from "react-router-dom";

const location = useLocation();
console.log(location.state) // gives: {username: 'user', password: '696'}
Comment

pass data between router components

import {useLocation} from 'react-router-dom';

const Register=()=>{

const location = useLocation()

//store the state in a variable if you want 
//location.state then the property or object you want

const Name = location.state.name

return(
  <div>
    hello my name is {Name}
  </div>
)

}
Comment

pass data between router components

<Link to='register' state={{name:'zayne'}}>
Comment

PREVIOUS NEXT
Code Example
Javascript :: livewire multiple root elements detected. this is not supported 
Javascript :: Control a progress bar for custom video player 
Javascript :: PostManDocs 
Javascript :: Exporting Objects with the Exports Object in electron 
Javascript :: How to remove added values with javascript 
Javascript :: How to Loop Through an Array with a do…while Loop in JavaScript 
Javascript :: Deployment of react static page using node and express 
Javascript :: Backbone Model Most Simple 
Javascript :: how to set javascript load order in html 
Javascript :: how to close bootstrap modal after save 
Javascript :: country select dropdown javascript 
Javascript :: quill js laravel 
Javascript :: Solution-4--solution options for reverse bits algorithm js 
Javascript :: javascript reducers 
Javascript :: javascript asynchronous function list 
Javascript :: flutter webview javascript 
Javascript :: js 
Javascript :: && condition in javascript 
Javascript :: js delete url params 
Javascript :: looping object 
Javascript :: js array append 
Javascript :: how to add suffix to a string in javascript 
Javascript :: get latest input by .each jquery 
Javascript :: what f a number exceeding 2^53 in javascript 
Javascript :: javascript Rename in the module 
Javascript :: javascript Undeclared objects are not allowed 
Javascript :: !Object.construct polyfill 
Javascript :: convert string to slug javascript 
Javascript :: javascript equality operator 
Javascript :: phaser shift position 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =