이이 질문은이 게시물에 관련이 반응한다.문제는 라우터 V4 및 MatchWithFade
내가 여기에서 가져온 <MatchWithFade>
예제를 사용하는 방법을 알아 내려고 노력 해요 :
https://react-router.now.sh/animated-transitions
제가 보는 문제는 그 나는 두 개의 탭이 있고, 나는 사이에 페이드하려면 그것들은 두 개의 탭 중 하나에서 페이드 효과 만 보았고 어떤 코드가 <MatchWithFade>
인 지에 따라 달라집니다.
관련 코드는 다음과 같습니다 :이 예에서
const One =() => {
return (
<div style={{position:'absolute', top: 0, left: 0, width: 300, backgroundColor: 'orange'}}>
One one one one one one one one one one
</div>
)
}
const Two =() => {
return (
<div style={{position:'absolute', top: 0, left: 0, width: 300, backgroundColor: 'yellow'}}>
Two two two two two two two two two two
</div>
)
}
class AppBody extends Component {
render() {
return (
<div style={{position: 'relative'}}>
<MatchWithFade pattern='/one' component={One} />
<MatchWithFade pattern='/two' component={Two} />
</div>
)
}
}
, 페이드가 발생하게됩니다 ((가) 라우터 <Link>
구성 요소에 반응하여), /one
로 이동,하지만 난 /two
로 이동하는 경우가있다 퇴색하지 마라. 그런 다음 <MatchWithFade pattern='/two' ... />
을 먼저 나열하면 /two
으로 페이드 전환이 표시되지만 /one
이 표시되지는 않습니다.
그냥 <Match>
을 사용하면 정상적으로 작동하므로 기본 설정 문제가 아닌 것 같습니다. <BrowserRouter>
입니다.
나는 바보 같은 짓을하기를 바라고있다. 그러나 내 인생에서 나는 무엇을 알 수 없다. 모든 지침을 부탁드립니다.
그것의 방법과 객체를 참조하는 방법을 알아낼 수없는 라우터 (반작용 사용하여 jsbin을 만들어하는 방법을 나는 오직 통해 RR을 사용한 이후로는 알아낼 수
UPDATE import 문). 그래서 여기 차선책이다 :이 MatchWithFade
사이의 매우 작은 차이가 있습니다
import React, { Component } from 'react';
import BrowserRouter from 'react-router/BrowserRouter'
import { TransitionMotion, spring } from 'react-motion'
import Match from 'react-router/Match'
import Link from 'react-router/Link';
const MatchWithFade = ({ component:Component, ...rest }) => {
const willLeave =() => ({ opacity: spring(0) })
return (
<Match {...rest} children={({ matched, ...props }) => {
return (
<TransitionMotion
willLeave={willLeave}
styles={matched ? [ {
key: props.location.pathname,
style: { opacity: 1 },
data: props
} ] : []}
>
{interpolatedStyles => {
return (
<div>
{interpolatedStyles.map(config => (
<div
key={config.key}
style={{...config.style }}
>
<Component {...config.data}/>
</div>
))}
</div>
)
}}
</TransitionMotion>
)
}}/>
)
}
const One =() => {
return (
<div style={{position:'absolute', top: 0, left: 0, width: 300, border: '1px solid black', backgroundColor: 'orange', minHeight: 200}}>
One one one one one one one one one one<br />
One one one one one one one one one one<br />
</div>
)
}
const Two =() => {
return (
<div style={{position:'absolute', top: 0, left: 0, width: 300, border: '1px solid black', backgroundColor: 'yellow', minHeight: 200}}>
Two two two two two two two two two two<br />
Two two two two two two two two two two<br />
</div>
)
}
class App extends Component {
render() {
return (
<BrowserRouter>
<div style={{padding: 12}}>
<div style={{marginBottom: 12}}>
<Link to='/one'>One</Link> || <Link to='/two'>Two</Link>
</div>
<div style={{position: 'relative'}}>
<MatchWithFade pattern='/one' component={One} />
<MatchWithFade pattern='/two' component={Two} />
</div>
</div>
</BrowserRouter>
)
}
}
export default App;
하고 반작용 라우터 문서에서 가져온 일이이 문제를 보여주는 완벽한 예입니다. 가장 큰 차이점은 내가 zIndex
참조를 꺼냈다는 것입니다.하지만 동작에는 영향을 미치지 않았습니다.
관련성이있는 경우 create-react-app
을 사용하여이 프로젝트를 시작했으며 대응 라우터 버전 4.0.0-alpha.6
을 사용하고 있습니다.
아무 것도 나에게 잘못으로 서 있지 않습니다. 스 니펫, 바이올린, jsbin, 모든 코드에서 선호하는 것이 무엇이든 함께 넣을 수 있습니까?(아마도 해시 라우터로 전환해야하지만 문제가 아니 어서 문제가되지 않을 것입니다.) –
확실히 시도 할 수 있습니다. 오늘이나 내일 할게. – hairbo
위의 원래 게시물에 전체 예제를 추가했습니다. 나는 cdnjs에서 React Router 4alpha6를 참조 할 수 있었지만'react-router/BrowserRouter'에서 'BrowserRouter 가져 오기'와 유사한 호출을 알아낼 수 없었기 때문에 메서드와 객체를 참조하는 방법을 알 수 없었다. . 어쨌든, 이것이 유용한 정보가되기를 바랍니다. 나는 아직도 내가 어리석은 짓을하고 있다고 가정하고있다. 어떤 지침이 도움이됩니다! – hairbo