現在、私はrails/react/reduxプロジェクトに取り組んでいます。私は最近、反応ルータ - レデュークス "^ 4.0.8"と反応ルータ "^ 3.0.2"を追加し、現在のLocationBeforeTransitioningがすべてのAPIリクエストURLに追加されました(つまり、http://localhost:3000/api/posts?term=“test”
であるはずですが、http://localhost:3000/categories/api/posts?term=“test”
をフェッチしようとしています)ポスト・コンポーネントReact Router Reduxは、API要求にLocationBeforeTransitionsを追加します。
プロジェクトはかなり大きいですが、私は以下のいくつかの潜在的に関連のスニペット含めました:。
routes.js
module.exports = (
<Route path="/" component={App}>
<IndexRedirect to="/categories"/>
<Route path="/categories" component={Categories}/>
<Route path="/:category" component={Posts}/>
<Route path="/categories/posts" component={Posts}/>
<Route path="/categories/:post" component={Citations}/>
…
<Route path="*" component={NotFound}/>
</Route>
)
configureStore.js
export default function configureStore(initialState) {
const composeEnhancers = composeWithDevTools({
})
const router = routerMiddleware(browserHistory);
const store = createStore(
rootReducer,
initialState,
composeEnhancers(
applyMiddleware(thunk, router)
))
…
を
actions.js
…
export function fetchPosts (term = '', random = false) {
return function(dispatch) {
fetch(`${API_URL}posts?term=${term}&random=${random}`, {
method: 'get',
headers: !sessionStorage.jwt ? default_header : auth_header
})
.then(response => response.json())
.then(json => {
if (!json || json.error) {
let default_error = 'An Error Occured.';
throw `Oops! ${json.exception || default_error}`;
}
dispatch(requestPostSuccess(term, json));
})
.catch(error => {
dispatch(requestPostError(error));
});
}
}
…
Posts.js
…
class Posts extends Component {
componentWillMount(){
if (this.props.location.pathname.slice(1).split('/')[0] == 'categories'){
this.props.actions.fetchPosts('', true)
}
}
…
誰もがこれを引き起こし、および/または回避策かもしれないものを知っていますか?
私にも起こります、解決策が見つかりましたか? – lironn