为Index中的脚本升级Angular得到404 Not Found

时间:2017-03-25 07:01:45

标签: angular angular4

我刚刚将我的项目从Angular 2.4.7和Angular CLI 1.0.0-beta.31升级到Angular 4.0.0和Angular CLI 1.0.0。自升级以来,我遇到以下错误:

font-awesome.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
material-icons.css Failed to load resource: the server responded with a status of 404 (Not Found)
global-styles.css Failed to load resource: the server responded with a status of 404 (Not Found)
hammer.js Failed to load resource: the server responded with a status of 404 (Not Found)

这些与我在index.html中的脚本引用有关。自升级以来我没有改变结构,有谁知道我为什么会收到这些错误?

的index.html

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Tellurium Platform</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">  
  <link rel="stylesheet" href="./app/library/css/font-awesome.min.css">  
  <link rel="stylesheet" href="./global-styles.css">
  <link rel="stylesheet" href="./app/library/css/material-icons.css">

  <link href="https://fonts.googleapis.com/icon?family=Material+Icons"
      rel="stylesheet">
  <!--For Material 2 slider elements-->
  <script src="./app/library/js/hammer.js"></script>
</head>
<body class="canvas">
  <app-root>Loading...</app-root>
</body>
</html>

2 个答案:

答案 0 :(得分:2)

将您的依赖项移动到.angular-cli.json文件下的此类脚本下

 "scripts": [
        ....,
        "./app/library/js/hammer.js"
      ],
  从最新的angulae cli

你必须在angular-cli.json文件中的脚本和样式标记下添加所有外部文件(css和js)

答案 1 :(得分:1)

查看此官方 release notes 文件夹结构已更改,您应该将路径更改为

<link rel="stylesheet" href="./src/app/library/css/font-awesome.min.css">  
  <link rel="stylesheet" href="./global-styles.css">
  <link rel="stylesheet" href="./src/app/library/css/material-icons.css">