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

get current url pathreact

console.log(window.location.pathname); //yields: "/js" (where snippets run)
console.log(window.location.href);     //yields: "https://stacksnippets.net/js"
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to convert string to sentence case in javascript 
Javascript :: antd react native 
Javascript :: image react native 
Javascript :: append line break javascript 
Javascript :: jshint ignore line 
Javascript :: what is polyfills in angular 
Javascript :: javascript count character in string 
Javascript :: includes method javascript 
Javascript :: how to make a string with unique characters js 
Javascript :: axios httponly cookie 
Javascript :: js get text from html string 
Javascript :: flatmap javascript 
Javascript :: hammer js 
Javascript :: ReactDOMServer import 
Javascript :: javascript arrow function 
Javascript :: jquery wait for element to load 
Javascript :: Contact form tutorial next.js 
Javascript :: jquery scroll to element in scrollable div 
Javascript :: vue js tutorial 
Javascript :: import svg as react component 
Javascript :: filter object by key name 
Javascript :: settimeout javascript 
Javascript :: setting usestate to prop 
Javascript :: json search javascript 
Javascript :: jquery get cursor position 
Javascript :: node.js name of file 
Javascript :: condition inner populate mongoose 
Javascript :: javascript compose function 
Javascript :: setstate find opject in state and update 
Javascript :: Cannot unpack array with string keys 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =