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 :: bfs javascript 
Javascript :: javascript add update query parameter to url 
Javascript :: how to use for of in javascript 
Javascript :: javascript full date as string 
Javascript :: react button onclick components 
Javascript :: javascript regex match character from a set of characters 
Javascript :: typescript vs javascript 
Javascript :: array pop 
Javascript :: js format string 2 digits 
Javascript :: url encoded body in node.js 
Javascript :: window location any web 
Javascript :: delete dom elements 
Javascript :: online javascript compiler 
Javascript :: enzynme not support react 17 
Javascript :: add multiple elements to set javascript 
Javascript :: js remove all child elements from html 
Javascript :: expresiones regulares javascript 
Javascript :: proxy nuxt 
Javascript :: how to encode uri in prereuqest script postman 
Javascript :: node express params 
Javascript :: nested dto nestjs 
Javascript :: Make Floating label TextInput in react native 
Javascript :: how to redirect a form to another page when we submitted a form in react js 
Javascript :: legend on click use default chartjs 
Javascript :: flatten json python 
Javascript :: react scroll on top while transition 
Javascript :: scroll bar disappears after closing modal 
Javascript :: conditional onclick react 
Javascript :: puppeteer 
Javascript :: jquery slider value 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =