在 dev lite-server 上工作的 SPA/page.js 中刷新页面导致请求中的 URL 错误

问题描述 投票:0回答:1

我有带有 page.js 的 SPA,用于在开发服务器上本地运行路由。 数据库服务器在 http://localhost:3030 端口上运行 开发服务器:http://localhost:3000 如果第一次在 url 中使用参数启动页面,则没有问题:borwser 使用正确的 url 从数据库服务器正确加载数据: http://localhost:3030/data/albums/6bb7659d-e094-4e6d-bc08-0901e6a8784e 页面网址为:http://localhost:3000/albums/6bb7659d-e094-4e6d-bc08-0901e6a8784e 但是当我尝试刷新页面时 浏览器尝试从这个错误的网址加载数据: http://localhost:3000/albums/6bb7659d-e094-4e6d-bc08-0901e6a8784e

app.js 也无法加载: http://localhost:3000/albums/src/app.js

显然开发服务器Lite-server将DB请求的localhost地址端口从3030更改为3000,这是他自己的地址,而不是DB服务器的正确localhost。 如何继续配置服务器,以便在不更改 url 请求的情况下正常工作?

我尝试找到 bs-confing.json 文件的一些设置,但它没有改变任何东西。

request localhost url-parameters lite-server
1个回答
0
投票

我找到了! index.js 中 script 元素的属性 src 中的路径 应该是绝对的

src="/src/app.js"
不是相对的
src="./src/app.js"

© www.soinside.com 2019 - 2024. All rights reserved.