获取 http://localhost:3000/dashboard/js/appclient.js net::ERR_



我知道有很多这样的问题,但我无法弄清楚为什么dashboard.html找不到appclient.js,但index.html可以找到appclient.js
我收到错误:GET http://localhost:3000/dashboard/js/appclient.js net::ERR_ABORTED 404 (Not Found)

应用.js

// /login redirects the client to /dashboard/:uid if correctly authenticated
app.route("/login")
.get((req,res) => {
res.sendFile('./public/index.html', {root: __dirname})
})
app.route("/dashboard/:uid")
.get((req,res) => {
res.sendFile('./public/dashboard.html', {root: __dirname})
})
app.use(express.static('public'))

索引.html

<!DOCTYPE html>
<html lang="de">
<head>
<script type="module" src="js/appclient.js" defer></script>
</head>
<body>
<myapp>
<h1> {{ title }} </h1>
</myapp>
</body>
</html>

仪表板.html

<!DOCTYPE html>
<html lang="en">
<head>
<script type="module" src="js/appclient.js" defer></script>
<title>Dash</title>
</head>
<body>
<h1>dash</h1>
</body>
</html>

应用程序客户端.js

import Vue from './lib/vue.esm.browser.js'
import VueResource from './lib/vue-resource.esm.js'
Vue.use(VueResource); 
const myApp = new Vue({
name: "myapp",
el: ' myapp',
data: {  // 
title: "Hello World!", 
}
})

文件夹结构

您正在使用相对于当前 URL 的路由,在这种情况下可能不起作用。我假设您使用express.static公开"公共"目录。js文件应可作为绝对路由访问,/js/appclient.js.

<script type="module" src="/js/appclient.js" defer></script>

最新更新