“React Get Route Path” Respostas de código

React Get Route Path

import { useLocation } from 'react-router-dom'

function HeaderView() {
  const location = useLocation();
  console.log(location.pathname);
  return <span>Path : {location.pathname}</span>
}

Strange Seahorse

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

React Route Path Exact


<Route exact path="/">
  <Home />
</Route>

# The exact prop above tells the Router component to match the path exactly. If you don't add the exact prop on the / path, it will match with all the routes starting with a / including /about.
Irfan

Respostas semelhantes a “React Get Route Path”

Perguntas semelhantes a “React Get Route Path”

Mais respostas relacionadas para “React Get Route Path” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código