“Cómo obtener URL en React” Código de respuesta

Cómo obtener URL actual con JavaScript o 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
Terrible Teira

Cómo obtener URL en React

window.location.href
Inquisitive Impala

Obtener el enrutador de reacción de URL actual

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

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

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

Obtener datos de URL usando React

this.props.match.params.id
John wick

Respuestas similares a “Cómo obtener URL en React”

Preguntas similares a “Cómo obtener URL en React”

Más respuestas relacionadas con “Cómo obtener URL en React” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código