【发布时间】:2021-07-06 03:03:53
【问题描述】:
我刚开始使用 Next JS,在 youtube 上关注 Brad Traversy's tutorial。我使用next export 导出程序,就像他在教程中所做的那样。我用serve -s out -p 8000。该页面在localhost:8000 上加载,但是当我转到localhost:8000/about 等其他链接时,它只是重新加载主页。
我在网上寻找解决方案,我尝试将"trailingSlash": true 添加到我的next.config.js 文件中,但仍然不起作用。
最令人困惑的部分是当点击页面上的链接元素(来自“next/link”模块)时,它可以工作,它会将我带到正确的页面。但是当我想直接从地址栏访问它时它不起作用。
顺便说一句,它在生产过程中也可以工作。
编辑
这是next.config.js 文件:
module.exports = {
trailingSlash: true,
};
这是package.json 文件:
{
"name": "next-cc",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"export": "next build && next export"
},
"dependencies": {
"next": "10.1.3",
"react": "17.0.2",
"react-dom": "17.0.2"
}
}
编辑:这是文件夹结构
这是项目的link
【问题讨论】:
-
能否通过在 URL 末尾添加
.html访问“关于”页面:localhost:8000/about.html? -
@juliomalves 但不,我也不能这样做
-
你能把你的完整
next.config.js发上来吗? -
@juliomalves 好的。我刚刚添加了它
-
@juliomalves 这是该项目的link
标签: javascript node.js reactjs next.js