В настоящее время я работаю над проектом rails / react / redux. Недавно я добавил response-router-redux «^ 4.0.8» и response-router «^ 3.0.2», и теперь текущий LocationBeforeTransitioning добавляется к каждому URL-адресу запроса API (т.е. должен быть: http://localhost:3000/api/posts?term=“test”
, но пытается получить http://localhost:3000/categories/api/posts?term=“test”
в компонент сообщений.
Проект довольно большой, но я включил несколько потенциально релевантных фрагментов ниже:
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)
}
}
…
Кто-нибудь знает, что может вызвать это и / или обходной путь?