页面已呈现,但当我按下任何链接时,它会出错.

ReferenceError: path is not defined
at app.get (/var/www/example.com/example-domain/server.js:106:19)
at Layer.handle [as handle_request] (/var/www/example.com/example-domain/node_modules/express/lib/router/layer.js:95:5)
at next (/var/www/example.com/example-domain/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/var/www/example.com/example-domain/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/var/www/example.com/example-domain/node_modules/express/lib/router/layer.js:95:5)
at /var/www/example.com/example-domain/node_modules/express/lib/router/index.js:281:22
at param (/var/www/example.com/example-domain/node_modules/express/lib/router/index.js:354:14)
at param (/var/www/example.com/example-domain/node_modules/express/lib/router/index.js:365:14)
at Function.process_params (/var/www/example.com/example-domain/node_modules/express/lib/router/index.js:410:3)
at next (/var/www/example.com/example-domain/node_modules/express/lib/router/index.js:275:10)

这是来自服务器的代码.js:

app.use(express.static('../build'));
app.get('*', (req, res)=> {
  const index = path.join(__dirname, '/', '../build', 'index.html' );
  res.sendFile(index);
});

提前谢谢.

推荐答案

在文件的开头,只需添加

const path = require('path');

Reactjs相关问答推荐

如何在Pivot模式下自定义标题?

Shadck/ui Select -当用户 Select 项目时更改状态

NextJS(AppRouter)、Apollo(客户端),在根布局中使用ApolloProvider时出错

如何通过浏览器路由在单独的.jsx文件中使用MUI抽屉?

是否在Extra Reducer完成作业(job)时触发createListenerMiddleware?

对搜索引擎优化来说,react 头盔的异步足够了吗?

Reaction路由DOM v6不包含上下文(Supabase)

滚动视图样式高度没有任何区别

单击按钮不会切换组件(当按钮和组件位于两个单独的文件中时)

我如何使用 React toastify (Promise) toast 和邮箱 js

在 React 中将 MUI 样式外包到单独的文件中?

Next.js 和理智 | npm run build 时预渲染页面/时发生错误

下一个js如何从另一个组件更新组件?

useEffect 渲染没有依赖数组的组件

单击按钮或文本从一个组件移动到另一个组件

如何从 React Redux store 中删除特定项目?

在 Formik 表单中访问子组件的值

在 Remix 中使用 chartjs 和 react-chartjs-2 会出现错误react-chartjs-2未在您的 node_modules 中找到

使用 React 中的功能组件更改另一个组件的状态

Axios 删除在带有授权令牌的react js 中不起作用