Next:ReferenceError: document is not defined
·
next配置路由报错 next ReferenceError: document is not defined,这个解决方案
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
原使用 react-router-dom修改为(建议)
import { useRouter } from 'next/router';
如果使用 react-router-dom需要使用动态或者使用到document或windows的函数方法都需要添加
// 动态引入
import dynamic from 'next/dynamic';
const TeacherForm = dynamic(() => import('./test/test'), {
loading: () => <h1>Loading...</h1>, // 加载占位符
});
// 添加判断window或document
if (typeof window === 'object') {
}
if (typeof document === 'object') {
}
这样太麻烦了
更多推荐

所有评论(0)