| 学习路线指引(点击解锁) | 知识定位 | 人群定位 |
|---|---|---|
| 🧡 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 (
-
相关阅读:
ubuntu install docker
项目经理在项目中起到的作用
HTTP请求的几种方式
一行代码,让 VS Code 内置 PDF 阅读器变成深色模式
Blender vs 3ds Max:谁才是3D软件的未来
还有人以为高并发=多线程吗?跟着大佬带你了解二者关系与区别,面试难题轻松拿下!
容器云平台监控告警体系(四)—— Golang应用接入Prometheus
智慧工地技术方案
Lwip之TCP协议实现(三)
java使用了未经检查或不安全的操作。的解决方法
-
原文地址:https://blog.csdn.net/u012804784/article/details/126239371