Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to get current URL with Javascript or React

const currentURL = window.location.href // returns the absolute URL of a page

const pathname = window.location.pathname //returns the current url minus the domain name
Comment

get url react

window.location.href
Comment

get current url react router

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

const SomeComponent = withRouter(props => <MyComponent {...props}/>);

class MyComponent extends React.Component {
  SomeMethod () {
    const {pathname} = this.props.location;
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to install yup in react native 
Javascript :: console.log clear screen 
Javascript :: express request body undefined 
Javascript :: mongodb connection string node example localhost 
Javascript :: code challenges javascript 
Javascript :: flatlist horizontal 
Javascript :: react js image path src from local folder 
Javascript :: js concat variable and string 
Javascript :: regexp constructor javascript 
Javascript :: safeareaview react native android 
Javascript :: add props to jsx element 
Javascript :: regex for email validation 
Javascript :: is typescript faster than javascript 
Javascript :: promise catch 
Javascript :: set label text in jquery 
Javascript :: jquery set input value 
Javascript :: jqiery check if scroll to end 
Javascript :: ngswitchcase in angular 8 
Javascript :: javascript random 4 digit number 
Javascript :: expressjs 
Javascript :: joi validation 
Javascript :: find in array and change 
Javascript :: js addeventlistener 
Javascript :: downgrade node version windows using npm 
Javascript :: joi object id validation 
Javascript :: javascript hashmap 
Javascript :: firebase read data javascript 
Javascript :: javascript loop and array 
Javascript :: javascript blob to file 
Javascript :: routes react 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =