내 응용 프로그램에서 react-router를 사용하기 시작하고 URL 끝에 슬래시 (_ 슬릭)가 있으면 작동하지 않습니다. 나는 그것에 대해 더 많이 조사하고, 모든 문서와 반응 라우터 문제를 읽고 <Redirect from='/*/' to="/*" />
을 사용하려했지만, 좋은 해결책은 아니었다. 그래서, 더 많은 것을 읽고 URL 끝에 /?
을 삽입하라는 제안을 발견했으나 여전히 효과가 없습니다.반응 라우터 URL에서 후행 슬래시를 제거하는 방법
routes.js의 코드 :
export default (
<Route path="/" component={App}>
<IndexRoute component={ProfileFillComponents} />
<Route path="/seguro-residencia" handler={require('./components/Forms/Residencial/ProfileFill/profileFillComponents')} />
<Route path="/seguro-residencia/informacoes-pessoais" component={CotationNumber} />
</Route>
)
하는 index.js의 코드 :
render((<Router history={browserHistory} routes={routes} />), document.getElementById('root'));
더 많은 검색, 내가 URL을에 슬래쉬 강제하는 함수를 만든 사람을 발견하고 나는 그것의 반대를 만들기로 결심했다. 기능
업데이트 routes.js 코드 없음 후행 슬래시 기능 : 다시
export default (
<Route onEnter={forceTrailingSlash} onChange={forceTrailingSlashOnChange}>
<Route path="/" component={App}>
<IndexRoute component={ProfileFillComponents} />
<Route path="/seguro-residencia" handler={require('./components/Forms/Residencial/ProfileFill/profileFillComponents')} />
<Route path="/seguro-residencia/informacoes-pessoais" component={CotationNumber} />
</Route>
</Route>
)
function forceNoTrailingSlash(nextState, replace) {
const path = nextState.location.pathname;
if (path.slice(-1) === '/') {
replace({
...nextState.location,
pathname: path.slice(1,path.lastIndexOf('/')-1)
});
}
}
function forceNoTrailingSlashOnChange(prevState, nextState, replace) {
forceNoTrailingSlash(nextState, replace);
}
그리고이 작동하지 않았다! 가능한 한이 URL을 좀 더 친숙하게 만들어야하며 마지막에 끝에 오는 슬래시가 없도록하고 싶습니다. 어떤 제안이라도 어떻게 만들 수 있습니까? 그리고 왜 Redirect
이이 경우에 작동하지 않았습니까?
해결책을 얻었습니까? 공유 할 수 있습니까? – myDoggyWritesCode
예, 있습니다! 나는 곧 나의 해결책을 게시 할 것이다. :) – Aipi
위대한. :) Thanks – myDoggyWritesCode