Reactjs 下一个链接

Reactjs 下一个链接,reactjs,redux,next.js,next,Reactjs,Redux,Next.js,Next,我正在使用NextJS和Redux,一切都很好,例如,当我转到主页时,我使用以下内容来获取ServerSideProps export const getServerSideProps = wrapper.getServerSideProps( async ({ store }) => { await store.dispatch(homePage.getFeaturedCompanies()); } ); 这使我可以通过应用程序中的useSelector anywher

我正在使用NextJS和Redux,一切都很好,例如,当我转到主页时,我使用以下内容来获取ServerSideProps

export const getServerSideProps = wrapper.getServerSideProps(
  async ({ store }) => {
    await store.dispatch(homePage.getFeaturedCompanies());
  }
);
这使我可以通过应用程序中的useSelector anywhere访问FeaturedCompanies。一切都好

const featuredCompaniesSelector = useSelector(getFeaturedCompanies);
问题是我想转到使用以下内容的博客页面:

export const getServerSideProps = wrapper.getServerSideProps(
  async ({ store }) => {
    await store.dispatch(blogPage.getPosts());
  }
);
博客页面无法加载,因为帖子中并没有数据,因为我假设它并没有水合,所以状态为空。若我刷新页面,它会工作,因为我有水化发生的数据

同样的道理,如果我从/blog开始,然后通过/blog工作到/home,我会得到一个无特征的公司错误

我不能解决的是,如何改变链接

我尝试在每个页面中通过useEffect发送,但出于某种原因,这似乎可以清除水合数据。我还尝试映射DispatchToprops connect,并在useEffect中使用它,但遇到了相同的问题

--更新-- 好的,我通过在页面加载上调度useEffect使其工作。似乎应该有比两次派遣更好的解决方案

仅供参考,useEffect没有像上面提到的那样工作的原因是因为数据不存在,所以我必须在默认状态中添加额外的细节