'난' 요소 '와' 반응을 러우터 사용할 수 있는 링크를 만들 수 있는 링크를 통해 기본적으로 처리됩니까 러우터 반응합니다.
I see it 페이징됩니다 내부적으로 '티스스콘티스트리트란스티언토 (.)'.
I want to do a 에서 드롭다운이 선택물을 링크를 통해 탐색 (단, 예를 들어. 이 코드를 어떻게 합니까? 지정하십시오. 티스스콘티스트 '?'
하지만 할 수 없이 이 이동줄에 봤다 '' 믹스인 믹스인?
>. V5.1.0 러우터 반응할 수 있는 후크를
'새' 우세이스토리 반응할 수 있습니다, 사용하는 경우, 16.8.0 > 반응할 수 있는 후크를 러우터 > 5.1.0 및 기능 구성 요소.
import { useHistory } from "react-router-dom";
function HomeButton() {
let history = useHistory();
function handleClick() {
history.push("/home");
}
return (
<button type="button" onClick={handleClick}>
Go home
</button>
);
}
>. 발빠르게 러우터 v4
반응할 수 있는 세 가지 방법을 통해 v4 의 라우터인지, 취할 수 있는 프로그램 내에서 경로설정을 구성 요소.
'역사' 주변에 주로 러우터 반응할 수 있는 래퍼 라이브러리. # 39 의 상호작용에 browser& '역사' 는 '빈다우스 시스토리' 당신꺼에요 색상에는 브라우저 및 해시보다 기록. 또한, 메모리 역사 때 유용한 don& # 39 노드전역 없는 환경을 조성할 수 있다. 이는 특히 유용한 모바일 앱 개발 ('기본 처리') 와 함께 유닛 테스트를 노드입니다.
두 가지 방법 '역사' 는 인스턴스에는 탐색: '푸시' 와 '굈'. 것 같은 경우 '역사', '찾았다' 는 새 위치를 추가하기에서는 배열입니다 격지에서 누름식 스토리지와의 굈 '와' 현재 위치에 어레이에는 대체할 새로운 하나. 이 경우 일반적으로 '누름식 탐색' 방법을 사용해야 할 것입니다.
초기의 극적인 러우터 했습니다, 그러나 v4 ',' 역사 '를 직접 만들 인스턴스입니다 < BrowserRouter>;;' 및 ',', ',' < HashRouter> < MemoryRouter> 구성요소가 있지만브라우저에, 해시보다 및 메모리 인스턴스를 만들 수 있습니다. 러우터 반응할 수 있는 속성 및 메서드 '역사' 를 통해 이용할 수 있는 '라우터' 에 해당하는 러우터 인스턴스입니다 컨텍스트로 객체에는.
'이' 역사 '제안' 을 투입하기로 한 비트루터 고차 컴포넌트인지 로케이터로 구성 요소. 액세스하려면 굈 '방법' 이 있습니다 누름식 '와' '컨텍스트로' 를 다룰 필요가 없다.
import { withRouter } from 'react-router-dom'
// this also works with react-router-native
const Button = withRouter(({ history }) => (
<button
type='button'
onClick={() => { history.push('/new-location') }}
>
Click Me!
</button>
))
',' 이 아니라, t, Route> < 컴포넌트인지 isn& # 39 일치 격지에서. It 항상 길이 없는 라우트하고 너회가 렌더링할 수 있으며 현재 위치를 일치시킵니다 . 이 같은 ',', '소품' 로 < Route> 컴포넌트인지 패스 비트루터 도왔으매 액세스할 수 있습니다 '역사' 방법 '역사' 를 통해 제안.
import { Route } from 'react-router-dom'
const Button = () => (
<Route render={({ history}) => (
<button
type='button'
onClick={() => { history.push('/new-location') }}
>
Click Me!
</button>
)} />
)
마지막 옵션은 쾌감을 느끼는 경우 사용할 경우에만 방정식입니다 React& 작업 # 39 의 컨텍스트로 모델이다. 비록 컨텍스트로 컨텍스트로 불안정한 API 는 옵션입니다, 해야 한다고 강조한 바 있다. [4] 및 [왜안돼요 사용하도록 컨텍스트로] 그들의 반응을 섹선에서 붽뎄. 그래서 현재 자신의 사용하여 위험!
const Button = (props, context) => (
<button
type='button'
onClick={() => {
// context.history.push === history.push
context.history.push('/new-location')
}}
>
Click Me!
</button>
)
// you need to specify the context type so that it
// is available within the component
Button.contextTypes = {
history: React.PropTypes.shape({
push: React.PropTypes.func.isRequired
})
}
1 과 2 는 가장 간단한 선택항목을 구현할 수 있으므로, 대부분의 응용 사례, 그들은 당신의 최고의 내기를.
< br/>;
또한 더 많은 지식을 얻을 수 있습니다 링크 URL 매개 변수 및 네스트된 routing.* 경로설정이 대한 from below)
경로설정을 반응할 수 있는 JS *< br/>;
[4]: https://facebook.github.io/react/docs/context.html # 컨텍스트로 왜안돼요 사용할 수
>. 반응을 러우터 5.1.0+ 오토메이티드 (> 후크를 사용하기 및 처리, 16.8)
'훅' 의 새로운 기능 및 프로그램적 요소를 실행하십시오 우세이스토리 사용할 수 있습니다.
import { useHistory } from "react-router-dom";
function HomeButton() {
let history = useHistory();
// use history.push('/some/path') here
};
>. 반응을 러우터 4.0.0+ 오토메이티드
4.0 에서, 어느 한 구성 요소를 사용하는 잔인하니 이력이 있다.
class Example extends React.Component {
// use `this.props.history.push('/some/path')` here
};
참고: 티s.프로프스트리스토리 존재하지 않는 경우, ',' 구성 요소를 통해 렌더링됩니다 < Route> 않았다. '&Lt 콩지름에 라우트를 경로 = " .";; 구성요소 = {} 의 유르콤프로넨스 티s.프로프스트리스토리 유르콤프로넨스 />, '알 수 있다.
>. 반응을 러우터 3.0.0+ 오토메이티드
에서 3.0 이상) 의 구성 요소를 사용하는 러우터 비호환성의 제안.
class Example extends React.Component {
// use `this.props.router.push('/some/path')` here
};
>. 반응을 러우터 2.4.0+ 오토메이티드
2.4 의 구성 요소를 사용하여 높은 잔인하니 주문하십시오 내려받습니다 러우터 비호환성의 제안) 의 구성 요소를.
import { withRouter } from 'react-router';
class Example extends React.Component {
// use `this.props.router.push('/some/path')` here
};
// Export the decorated class
var DecoratedExample = withRouter(Example);
// PropTypes
Example.propTypes = {
router: React.PropTypes.shape({
push: React.PropTypes.func.isRequired
}).isRequired
};
>. 반응을 러우터 2.0.0+ 오토메이티드
이 버전은 호환됩니까 1.x 그러하매 there& # 39 의 업그레이드 안내선 뒤로 필요가 없습니다. 그냥 거치지 참조용이므로 아주 재미나겠네 부족합니다.
즉, 만약 새로운 패턴을 프로파일링하려는 전환하십시오 there& 브라우세르히스토리 모듈에서는 러우터 액세스할 수 있는 s # 39, 안에 있는
이제 브라우저를 액세스하도록 누름식, 교체 등) 와 같은 것들을 할 수 있도록) 이다. 다음과 같습니다.
'' 브라우세르히스토리오푸쉬 (& # 39, /some/path& # 39;)
추가 정보: [역사] (https://github.com/reactjs/react-router/blob/latest/docs/guides/Histories.md) 와 [이동줄에] (https://github.com/reactjs/react-router/blob/latest/docs/guides/NavigatingOutsideOfComponents.md)
>. 반응을 러우터 오토메이티드 1.x.x
I will not go into 업그레이드하기를 세부내용에서. [업그레이드합니다 안내선] (https://github.com/rackt/react-router/blob/master/upgrade-guides/v1.0.0.md) 의 읽을 수 있습니다
다음은 주요 변경 질문에 대해 변화를 믹스인 이동줄에 역사가. 그래서 지금 it& # 39 의 브라우저 사용에 흐리스토리아피 라우트를 변경하시려면 푸시국가 () '' 지금부터 사용하겠습니다.
var Example = React.createClass({
mixins: [ History ],
navigateToHelpPage () {
this.history.pushState(null, `/help`);
}
})
참고로 이 완료되니라 '역사' 에서 [락스 / 역사] (https://github.com/rackt/history) 를 부활시켰다. 반응을 러우터 아닌 것이다.
[1.0.x 문서용으로] 때 자신의 새로운 릴리스에는 대해 더 많이 읽을 수 있습니다 (https://github.com/rackt/react-router/tree/1.0.x/docs)
이것은 [도움말 페이지가 외부에 구체적으로 탐색 컴포넌트] (https://github.com/rackt/react-router/blob/1.0.x/docs/guides/advanced/NavigatingOutsideOfComponents.md)
It 는 해 () '와' 역사 '에서' = 크리스 히스토리 참조입니다 호출하십시오 레프리스국가 iqn.
>. 반응을 러우터 오토메이티드 0.13.x
I got into the 동일한 문제와 함께 제공되는 반응을 러우터 탐색 믹스인 통해 솔루션을 찾을 수 밖에.
import React from 'react';
import {Navigation} from 'react-router';
let Authentication = React.createClass({
mixins: [Navigation],
handleClick(e) {
e.preventDefault();
this.transitionTo('/');
},
render(){
return (<div onClick={this.handleClick}>Click me!</div>);
}
});
내가 필요 없이 스콘티스트 액세스하려면 트란스티언토 수 있었다 () '' '콜'
'클래스' 를 시도하시겠습니까 돌림무늬 ES6 수도 있습니다
import React from 'react';
export default class Authentication extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick(e) {
e.preventDefault();
this.context.router.transitionTo('/');
}
render(){
return (<div onClick={this.handleClick}>Click me!</div>);
}
}
Authentication.contextTypes = {
router: React.PropTypes.func.isRequired
};
>. 반응을 러우터 러더스 >. >. Note: you& 러더스 사용하는 경우, re # 39 라는 프로젝트 또 있다. >. [반응을 러우터 러더스] (https://github.com/reactjs/react-router-redux) 를 제공합니다. >. 같은 방식을 사용하여 러더스 위한 바인딩을 레이스트라우터 다소 >. [러더스 반응할] (https://github.com/rackt/react-redux) 가
몇 가지 방법을 사용할 수 있는 간편한 탐색 작업이 작성자 내부에서 반응을 러우터 러더스 사용할 수 있다. 특히 유용할 수 있습니다) 에 있는 사람들이 이러한 기존 아키텍처입니다 발빠르게 반응할 수 있는 상용 웹 동일한 패턴을 넷윈을 매개변수이므로 활용할 수 있도록 하는 최소한의 오버헤드에.
다음 방법을 살펴보았으므로.
'-' 누름식 (위치) '-' 복귀시킴 (위치) go (번호임) '-' 고백 () '-' 고포워드 () '-'
예를 들어보겠습니다 사용, 와 [러더스 썽크] (https://www.npmjs.com/package/redux-thunk):
./actioncreators.js
import { goBack } from 'react-router-redux'
export const onBackPress = () => (dispatch) => dispatch(goBack())
./viewcomponent.js
<button
disabled={submitting}
className="cancel_button"
onClick={(e) => {
e.preventDefault()
this.props.onBackPress()
}}
>
CANCEL
</button>
>. 반응을 러우터 v2
('V2.0.0-rc5') 에 대한 최신 릴리스에는 권장됨 이동줄에 방법은 직접 드래그합니다 싱글턴 추진하고 있다. In action < 있는 것을 볼 수 있습니다;;;; a href = " https://github.com/rackt/react-router/blob/master/docs/guides/NavigatingOutsideOfComponents.md" > 구성 탐색 바깥쪽인지가 /a> doc<;).
관련 발췌문:
import { browserHistory } from 'react-router';
browserHistory.push('/some/path');
새로운 반응을 러우터 api 를 사용하는 경우 활용할 수 있도록 해야 합니다 "에서 '역사' 구성 '을 (를) 인사이드라면 티s.프로프스 있습니다.
this.props.history.push('/some/path');
또한 그것은 더 이상 사용되지 않는 '당' 은 푸시국가 로깅된 개의경고.
',' 는 '누름식' 기능을 사용하는 경우 이 같은 발송하십시오 반응을 러우터 러더스 수 있습니다.
import { push } from 'react-router-redux';
this.props.dispatch(push('/some/path'));
그러나 이 데만 uirl 변경하십시오 아니라 실제로 탐색하십시오 페이지 수 있습니다.
import React from 'react';
export default class MyComponent extends React.Component {
navigateToPage = () => {
this.context.router.push('/my-route')
};
render() {
return (
<button onClick={this.navigateToPage}>Go!</button>
);
}
}
MyComponent.contextTypes = {
router: React.PropTypes.object.isRequired
}
>. 반응을 러우터 4.x 오토메이티드 :
내 말 하나만 갖고 싶어요 객체에는 외부에서도 컴포넌트와의 부착할 수 있다. 내가 할 수 있는 파일 하나만 왓 아이 라이크 흐리스토리자이스 가져오기의 on demand), 그리고 그냥 조작하는.
그냥 '제안' 을 바꿔야 할 브로스로우터 라우터인지, 지정하고 있다. 단, t # 39 이 doesn& 아무것도 바꾸지 당신꺼에요 조작할 수 있는 것이므로, 스스로 역사를 객체에는 있습니다.
1, [역사] 설치에 필요한 라이브러리를 사용하는 '반응을 러우터'.
예 사용, ES6 표기법:
import createBrowserHistory from 'history/createBrowserHistory'
export default createBrowserHistory()
import React, { Component } from 'react';
import history from './history';
class BasicComponent extends Component {
goToIndex(e){
e.preventDefault();
history.push('/');
}
render(){
return <a href="#" onClick={this.goToIndex}>Previous</a>;
}
}
>. 16일 4월 2018년 : 편집하십시오
이는 실제로 내비게이트할 경우 '에서' 에서 컴포넌트인지 렌더링됩니다 라우트를 컴포넌트용, 소품, like that history 를 액세스할 수 있습니다.
import React, { Component } from 'react';
class BasicComponent extends Component {
navigate(e){
e.preventDefault();
this.props.history.push('/url');
}
render(){
return <a href="#" onClick={this.navigate}>Previous</a>;
}
}
한 편, 이 때문에, 이를 위해 않는 사람이 제어입니다 서버만을 해시보다 러우터 v2 를 사용하고 있습니다.
역사 에 배치하십시오 별도의 파일 (예를 들어 app_history.js ES6):
import { useRouterHistory } from 'react-router'
import { createHashHistory } from 'history'
const appHistory = useRouterHistory(createHashHistory)({ queryKey: false });
export default appHistory;
이를 사용하여 및 상용화!
네 초급 반응을 러우터 (아프자이스 es6):
import React from 'react'
import { render } from 'react-dom'
import { Router, Route, Redirect } from 'react-router'
import appHistory from './app_history'
...
const render((
<Router history={appHistory}>
...
</Router>
), document.querySelector('[data-role="app"]'));
네 이동줄에 내의 구성 요소 (ES6):
import appHistory from '../app_history'
...
ajaxLogin('/login', (err, data) => {
if (err) {
console.error(err); // login failed
} else {
// logged in
appHistory.replace('/dashboard'); // or .push() if you don't need .replace()
}
})
>. # 반응을 러우터 V4
tl; dr.
if (navigate) {
return <Redirect to="/" push={true} />
}
>. 누름식: true 이면 부울을 리디렉션하는 추진할 새로운 역사를 초급형 드래그합니다 교체하는 대신 현재 1.
import { Redirect } from 'react-router'
class FooBar extends React.Component {
state = {
navigate: false
}
render() {
const { navigate } = this.state
// here is the important part
if (navigate) {
return <Redirect to="/" push={true} />
}
// ^^^^^^^^^^^^^^^^^^^^^^^
return (
<div>
<button onClick={() => this.setState({ navigate: true })}>
Home
</button>
</div>
)
}
}
[3]: https://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html # 초기화 es7 속성
>. Warning: 미디어만을 레이스트라우터 버전 1.0 이 대답이 닫히지만 전에
>. 내아기마저도 업데이트이 오토메이티드 1.0.0-rc1 활용 사례를 통해 후!
너무 믹스인 않고 이 작업을 수행할 수 있습니다.
let Authentication = React.createClass({
contextTypes: {
router: React.PropTypes.func
},
handleClick(e) {
e.preventDefault();
this.context.router.transitionTo('/');
},
render(){
return (<div onClick={this.handleClick}>Click me!</div>);
}
});
함께 있는 것이 장점 컨텍스트로 정의하십시오 콘테스티페스 않으면 '클래스' 에 접근할 수 없습니다.
이 프로그램은 객체에는 경우와 마찬가지로 지정하십시오. 컨텍스트로, 소품, 전달되는 것이 필요 없이 아이를 뒤쫓아 상위입니다 가미카제다 암시적으로 때마다 소품 재 선언. Https://www.tildedave.com/2014/11/15/introduction-to-contexts-in-react-js.html 참조
이렇게 하면 뭔가 협력했습니다 전에 전화했는데 적어도 10 가지 그래!
>. 함께 반응을 러우터 3.x.x es6:
import { withRouter } from 'react-router';
class Example extends React.Component {
// use `this.props.router.push('/some/path')` here
};
// Export the decorated class
export default withRouter(Example);
withRouter(Example);
export { Example };
참고로, 이 ',', '구성 자체가 3.x.x < Link> 루터스푸시 반드시 통과시킬 수 있도록 사용하여', '=' 태그, 뭐든 < https://partner. microsoft. 다음과 같은 것이다.
this.props.router.push({pathname: '/some/path', query: {key1: 'val1', key2: 'val2'})'
프로그래밍 할 수 있는 새로운 프로프스트리스토리 푸시할 이동줄에 합니다 구성 요소 '역사' 를 사용할 수 있는, 그래서 이 같은 일이 수행할 수 있습니다.
//using ES6
import React from 'react';
class App extends React.Component {
constructor(props) {
super(props)
this.handleClick = this.handleClick.bind(this)
}
handleClick(e) {
e.preventDefault()
/* Look at here, you can add it here */
this.props.history.push('/redirected');
}
render() {
return (
<div>
<button onClick={this.handleClick}>
Redirect!!!
</button>
</div>
)
}
}
export default App;
하지만 최고의 외곽진입 않을 수도 있습니다. V4, 반응을 러우터 사용하여 다음 타입스크립트 알 줄 수 있다.
예를 들어, '아래', '라우터' 의 렌더링됨 컴포넌트인지 로지 페이지 액세스됩니다 객체에는 루터스트란스티언토 (& # 39, /homepage& # 39;) '및' 농구계의 내비게이트할.
탐색 코드는 수행됨을 from.
'react-router" ";: '4.0.0-2" " ^;; 'react" ";: '15.3.1" " ^;;
<! - begin 스니핏: js 숨기십시오: 거짓값 콘솔: 진정한 바벨. > 거짓값 -;
import Router from 'react-router/BrowserRouter';
import { History } from 'react-history/BrowserHistory';
import createHistory from 'history/createBrowserHistory';
const history = createHistory();
interface MatchWithPropsInterface {
component: typeof React.Component,
router: Router,
history: History,
exactly?: any,
pattern: string
}
class MatchWithProps extends React.Component<MatchWithPropsInterface,any> {
render() {
return(
<Match {...this.props} render={(matchProps) => (
React.createElement(this.props.component, this.props)
)}
/>
)
}
}
ReactDOM.render(
<Router>
{({ router }) => (
<div>
<MatchWithProps exactly pattern="/" component={LoginPage} router={router} history={history} />
<MatchWithProps pattern="/login" component={LoginPage} router={router} history={history} />
<MatchWithProps pattern="/homepage" component={HomePage} router={router} history={history} />
<Miss component={NotFoundView} />
</div>
)}
</Router>,
document.getElementById('app')
);
끝 - < 스니핏 >;!
하지만 내가 펠리페 스키너 (end to end) 를 추가한 데 이어 솔루션이므로 초보자 like me.
다음은 내가 버전으로 사용합니다.
>. react-router" ";: " ^ 2.7.0";
>. react" ";: " ^ 15.3.1";
아래는 사용되는 프로그래밍 가능한 컴포넌트를 사용하여 어디서 이동줄에 반응을 러우터 내 반응을 보인다.
import React from 'react';
class loginComp extends React.Component {
constructor( context) {
super(context);
this.state = {
uname: '',
pwd: ''
};
}
redirectToMainPage(){
this.context.router.replace('/home');
}
render(){
return <div>
// skipping html code
<button onClick={this.redirectToMainPage.bind(this)}>Redirect</button>
</div>;
}
};
loginComp.contextTypes = {
router: React.PropTypes.object.isRequired
}
module.exports = loginComp;
import { Router, Route, IndexRedirect, browserHistory } from 'react-router'
render(<Router history={browserHistory}>
<Route path='/' component={ParentComp}>
<IndexRedirect to = "/login"/>
<Route path='/login' component={LoginComp}/>
<Route path='/home' component={HomeComp}/>
<Route path='/repair' component={RepairJobComp} />
<Route path='/service' component={ServiceJobComp} />
</Route>
</Router>, document.getElementById('root'));
사용할 수 있는 '비트루터 지정된 클래스 기반 컴포넌트, 시도하시겠습니까' 이 같은 일이 있습니다.
class YourClass extends React.Component {
yourFunction = () => {
doSomeAsyncAction(() =>
this.props.history.push('/other_location')
)
}
render() {
return (
<div>
<Form onSubmit={ this.yourFunction } />
</div>
)
}
}
export default withRouter(YourClass);
이전 오토메이티드 따라 충스러웠으니 Jos& # 233. 안토니오 포스티고, 벤 휠러 이 신규성? 반드시 서면으로 타입스크립트
import * as React from "react";
import Component = React.Component;
import { withRouter } from "react-router";
export interface INavigatorProps {
router?: ReactRouter.History.History;
}
/**
* Note: goes great with mobx
* @inject("something") @withRouter @observer
*/
@withRouter
export class Navigator extends Component<INavigatorProps, {}>{
navigate: (to: string) => void;
constructor(props: INavigatorProps) {
super(props);
let self = this;
this.navigate = (to) => self.props.router.push(to);
}
render() {
return (
<ul>
<li onClick={() => this.navigate("/home")}>
Home
</li>
<li onClick={() => this.navigate("/about")}>
About
</li>
</ul>
)
}
}
/**
* Non decorated
*/
export class Navigator2 extends Component<INavigatorProps, {}> {
static contextTypes = {
router: React.PropTypes.object.isRequired,
};
navigate: (to: string) => void;
constructor(props: INavigatorProps, context: any) {
super(props, context);
let s = this;
this.navigate = (to) =>
s.context.router.push(to);
}
render() {
return (
<ul>
<li onClick={() => this.navigate("/home")}>
Home
</li>
<li onClick={() => this.navigate("/about")}>
About
</li>
</ul>
)
}
}
있는모든 고궁박물원 설치되어 있는 오늘. react-router" ";: " ^ 3.0.0"; 및 @types/react-router" ";: " ^ 2.0.41";
반응할 수 있는 러우터 v4. 나는 이 길을 따라 두 회사가 경로설정할.
1. this.props.history.push("/something/something")
2. this.props.history.replace("/something/something")
2 번
>. 현재 엔트리여야 덮어씁니다 스택할) 에
소품 afaq 역사에 구성 요소를 함께 마무리 할 수 있습니다. >. 비트루터
반응을 러우터 v4 를 통해 새로운 방식으로 업무를 수행하는 지평면을, 이제 이.
import { MemoryRouter, BrowserRouter } from 'react-router';
const navigator = global && global.navigator && global.navigator.userAgent;
const hasWindow = typeof window !== 'undefined';
const isBrowser = typeof navigator !== 'undefined' && navigator.indexOf('Node.js') === -1;
const Router = isBrowser ? BrowserRouter : MemoryRouter;
<Router location="/page-to-go-to"/>
[레고 반응할] (https://github.com/peter-mouland/react-lego) 는 예를 들어 있는 앱을 fs@snapa [사용 방법 / 업데이트 반응을 러우터] (https://github.com/peter-mouland/react-lego/compare/react-router-4) 와 포함하고 있는 예제에서와 실행하십시오 기능 테스트 앱.
현재 버전 반응할 수 있는 티s.프로프스트리스토리오푸쉬 (& # 39, /location& # 39;), (15.3) ',' 나를 위해 협력했습니다 있지만 이 조사에서는 다음과 같은 경고:
>. browser.js:49 경고: [반응을 러우터] '와' 프로프스트리스토리 >. '콘테스트리시스토리' 이 더 이상 사용되지 않습니다. '' 콘테스트롬루터 사용하십시오.
저는 '해결' 를 사용하여 해당 콘테스트롬루터 다음과 같습니다.
import React from 'react';
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.backPressed = this.backPressed.bind(this);
}
backPressed() {
this.context.router.push('/back-location');
}
...
}
MyComponent.contextTypes = {
router: React.PropTypes.object.isRequired
};
export default MyComponent;
반응을 러우터 v4
dispatch(navigateTo("/aboutUs"));