| 学习路线指引(点击解锁) | 知识定位 | 人群定位 |
|---|---|---|
| 🧡 Python实战微信订餐小程序 🧡 | 进阶级 | 本课程是python flask+微信小程序的完美结合,从项目搭建到腾讯云部署上线,打造一个全栈订餐系统。 |
| 💛Python量化交易实战💛 | 入门级 | 手把手带你打造一个易扩展、更安全、效率更高的量化交易系统 |
正文从这开始~
当我们尝试在react router的Router上下文外部使用useNavigate 钩子时,会产生"useNavigate() may be used only in the context of a Router component"警告。为了解决该问题,只在Router上下文中使用useNavigate 钩子。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wEeOCwjb-1659978698940)(https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/85f51fba0bef4f76a1e7db8f522e0aec~tplv-k3u1fbpfcp-watermark.image?)]
下面是一个在index.js文件中将React应用包裹到Router中的例子。
// index.js
import {createRoot} from 'react-dom/client';
import App from './App';
import {BrowserRouter as Router} from 'react-router-dom';
const rootElement = document.getElementById('root');
const root = createRoot(rootElement);
// 👇️ wrap App in Router
root.render(
Router>
);
现在,你可以在App.js文件中使用useNavigate钩子。
// App.js
import React from 'react';
import {
useNavigate,
} from 'react-router-dom';
export default function App() {
const navigate = useNavigate();
const handleClick = () => {
// 👇️ navigate programmatically
navigate('/about');
};
return (
-
相关阅读:
【【萌新的Risc-V学习之再看读不懂的流水线设计-10】】
OpenvSwitch 子项目 OVN 功能介绍(一)
SQLServer 数据库语句可以执行但是语句会有红线提示错误
力扣第55题 跳跃游戏 c++ 贪心 + 覆盖 加暴力超时参考
MySQL8窗口函数应用
HTML快速入门
java高级编程day23【谷】
流水线的dependence问题(指令相关性)
(一)逻辑回归及其代价函数 --- 吴恩达深度学习笔记
使用CXF调用WSDL(二)
-
原文地址:https://blog.csdn.net/u012804784/article/details/126239371