javascript - 如何在下一个 js 中使用带有浅路由的 router.push?
问题描述
我是下一个 js 的初学者。我知道下一个 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]);
推荐阅读
- php - 如何将可重复的数据记录到数据库中
- dialogflow-es-fulfillment - 在对话框流的内联编辑器中编辑 Fulfillment 后如何保存
- python - 我如何做到这一点,所以我只需要引用一次我的 api 密钥?
- python - 如何使用 REST API 提取 aws CloudTrail 日志
- angular6 - ng-otp-input 不能很好地支持输入 0
- swift - 如何在swift中修复'无法将'[Any]'类型的值转换为强制类型'String''错误
- matlab - 如何使用循环在不同的图表中绘制不同的文件信息
- angular - 如何在 AppComponent 级别有不同的布局?
- html - 在社交网络上分享时如何显示网站徽标
- python - 如何从列表行创建单个列表?