【问题标题】:GET http://localhost:3000/dashboard/js/appclient.js net::ERR_ABORTED 404 (Not Found)GET http://localhost:3000/dashboard/js/appclient.js net::ERR_ABORTED 404(未找到)
【发布时间】:2020-04-13 14:38:27
【问题描述】:

我知道有很多这类问题,但我不明白为什么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

【问题讨论】:

  • Dashboard.html 在localhost:3000/dashboard/js 查找.js。这也是仪表板路线的终点。请考虑阅读 express、vue 等的文档。更多。您没有按预期使用应用程序的任何部分...

标签: javascript express vue.js


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-24
    • 1970-01-01
    • 2019-12-11
    • 2020-07-10
    • 2023-03-12
    • 2021-07-13
    • 1970-01-01
    • 2021-09-15
    相关资源
    最近更新 更多