Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react get current route

/*In the 5.1 release of react-router there is a hook called useLocation,
which returns the current location object. 
This might be useful any time you need to know the current URL.*/
import { useLocation } from 'react-router-dom';

const location = useLocation();
console.log(location.pathname);

Comment

how to know the current route in react class component

/*For class based components*/
import { withRouter } from 'react-router-dom';

class SomeComponent extends Component {
  render() {
    console.log(this.props.location)
    console.log(this.props.location.pathname)
    console.log(this.props.location.match)
    return <div>Something</div>
  }
}

export default withRouter(SomeComponent)
Comment

PREVIOUS NEXT
Code Example
Javascript :: adding jquery from console 
Javascript :: react index.js file 
Javascript :: npm run dev mix not found 
Javascript :: double click in jquery 
Javascript :: remove header border react native 
Javascript :: jquery select by name 
Javascript :: dconf-editor install 
Javascript :: javascript remove all spaces from string 
Javascript :: angular open poort in network 
Javascript :: js remove last character from string 
Javascript :: bcrypt_lib.node not found 
Javascript :: electron hide menu bar 
Javascript :: javascript convert string to 2 decimal 
Javascript :: body-parser deprecated undefined extended provide extended option 
Javascript :: window open same tab 
Javascript :: content of page fully loaded javascript 
Javascript :: bootstrap italics 
Javascript :: create random 4 digit number js 
Javascript :: ajax get request 
Javascript :: node get all files in folder 
Javascript :: vanilla js on click 
Javascript :: how to get value and key in a for of loop in js 
Javascript :: node log without newline 
Javascript :: remove a special character from string javascript 
Javascript :: remove square brackets from string javascript 
Javascript :: react simbu 
Javascript :: integer to roman javascript 
Javascript :: Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps 
Javascript :: ng serve host 0.0.0.0 
Javascript :: array join javascript new line 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =