GET http:// localhost:3000 / dashboard / js / appclient.js net :: ERR_ABORTED 404(未找到)

时间:2019-12-21 12:21:16

标签: javascript express vue.js

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

app.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'))

index.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>

dashboard.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>

appclient.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!", 
    }
})

Folder Structure

1 个答案:

答案 0 :(得分:0)

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

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