In my react project i need to make a condition on redux action according to the page location.
So i have used window.location.href
to get value of the current page but it returns the last visited page value.
export const getBlog = (type, offset) => {
console.log(window);
console.log(window.location.pathname);
if( window.location.pathname !== '/planner' ){
return (dispatch) => {
dispatch({ type: 'BLOG_LOADING_START'})
axios.get(siteurl + TPW.CATEGORY_API + type, {
headers: { 'Content-Type': 'application/json' } })
.then(response => {
let ary = response.data.slice(0, offset)
dispatch({
type: 'SET_BLOG_DATA',
list: response.data,
blogData: ary,
total: response.data.length,
offSetCnt: 3
})
dispatch({ type: 'BLOG_LOADING_DONE'})
});
}
}
}
First console.log(window)
screenshot; which returns an actual visited page location result.
Second console.log(window.location.pathname)
which returns previous visited page value.