“Como obter URL no React” Respostas de código

Como obter URL atual com JavaScript ou 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

Como obter URL no React

window.location.href
Inquisitive Impala

Obtenha o roteador atual de URL React

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

Obtenha dados do URL usando o React

this.props.match.params.id
John wick

Respostas semelhantes a “Como obter URL no React”

Perguntas semelhantes a “Como obter URL no React”

Mais respostas relacionadas para “Como obter URL no React” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código