난 그냥 반응 라우터의 V4를 사용하기 시작했다 현재 위치를 얻을 반응 나는이 내가에 따라 시도는 라우터가 V4
import {Meteor} from 'meteor/meteor';
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import createHistory from 'history/createBrowserHistory'
import {Route, BrowserRouter as Router, Switch} from 'react-router-dom'
import {Tracker} from 'meteor/tracker';
import Signup from '../imports/ui/signUp';
import Link from '../imports/ui/link';
import Login from '../imports/ui/login';
import NotFound from '../imports/ui/notFound';
const history = createHistory();
const unauthenticatedPages = ['/', '/signup'];
const authenticatedPages = ['/links'];
const routes = (
<Router history={history}>
<Switch>
<Route exact path="/" component={Login}/>
<Route exact path="/signup" component={Signup}/>
<Route path="/links" component={Link}/>
<Route component={NotFound}/>
</Switch>
</Router>
);
Tracker.autorun(() => {
const unlisten = history.listen((location, action) => {
// location is an object like window.location
console.log(action, location.pathname, location.state)
})
const isAuthenticated = !!Meteor.userId();
console.log('location: ', location.pathname);
//const pathName =
});
Meteor.startup(() => {
ReactDOM.render(routes, document.getElementById('app'));
});
내 소스 코드 라우터
의 현재 위치를 얻는 방법을 알고 싶어요 반응 라우터 문서는 역사를 사용하지만 위치를 얻지 못했습니다.
경로의 현재 위치를 얻는 방법은 무엇입니까?
나는 redux를 사용하지 않고 답변을 주시면 감사하겠습니다.
감사합니다.
경로 구성 요소에 일치 항목을 전달하여 하위 구성 요소에 일치 위치를 전달할 수 있습니다. 이 방법은 경로 구성 요소를 연결하는 데 사용됩니다. –