首页 > 解决方案 > 如何在下一个 js 中使用带有浅路由的 router.push?

问题描述

我是下一个 js 的初学者。我知道下一个 js 路由是如何工作的,但是浅层路由在我的项目中没有像我预期的那样工作。请分享有关它的有用资源,除了官方文档

标签: javascriptreactjsnext.js

解决方案


你可以试试这个方法。

import { withRouter } from "next/router";
import Router from "next/router";
const ComponentName= ({ router }) => {
//.......
Router.replace(`/`); // here will be location

}
export default withRouter(ComponentName);

如果仍然无法正常工作,请尝试使用uesEffect()

  useEffect(() => {

    // you initial function

  }, [router]);

推荐阅读