“React Zdobądź ścieżkę trasy” Kod odpowiedzi

React Zdobądź ścieżkę trasy

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

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

Strange Seahorse

Zdobądź bieżący router reagujący URL

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

Dokładna ścieżka trasy reaguj


<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

Odpowiedzi podobne do “React Zdobądź ścieżkę trasy”

Pytania podobne do “React Zdobądź ścieżkę trasy”

Więcej pokrewnych odpowiedzi na “React Zdobądź ścieżkę trasy” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu