admin管理员组文章数量:1404458
Have an angular application:
This is part of my index.html page:
<!DOCTYPE html>
<html lang="en" ng-app="ReApp">
<head>
<meta charset="UTF-8">
<title>REApp</title>
<link rel="stylesheet" href="./lib/bootstrap/dist/css/bootstrap.min.css">
<script src="./lib/angular/angular.min.js"></script>
</head>
<body></body>
</html>
This is part of my server.js(start point):
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/public'));
app.use('/api', api);
app.get('*', function(req, res){
res.sendFile(__dirname + '/public/app/views/index.html');
});
Problem is: when i have one route (localhost:3000/first) everything working. When i have route something like that: localhost:3000/first/second, i have an error "Resource interpreted as Stylesheet but transferred with MIME type text/html". In the terminal i have get request - first/second/lib/angular/angular.min.js. Of course i don't have that link. May who knows how to set a start page for this links in undex.html?
Have an angular application:
This is part of my index.html page:
<!DOCTYPE html>
<html lang="en" ng-app="ReApp">
<head>
<meta charset="UTF-8">
<title>REApp</title>
<link rel="stylesheet" href="./lib/bootstrap/dist/css/bootstrap.min.css">
<script src="./lib/angular/angular.min.js"></script>
</head>
<body></body>
</html>
This is part of my server.js(start point):
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/public'));
app.use('/api', api);
app.get('*', function(req, res){
res.sendFile(__dirname + '/public/app/views/index.html');
});
Problem is: when i have one route (localhost:3000/first) everything working. When i have route something like that: localhost:3000/first/second, i have an error "Resource interpreted as Stylesheet but transferred with MIME type text/html". In the terminal i have get request - first/second/lib/angular/angular.min.js. Of course i don't have that link. May who knows how to set a start page for this links in undex.html?
Share Improve this question asked Sep 10, 2015 at 15:02 Eugeniusz ZuevEugeniusz Zuev 1494 silver badges15 bronze badges 2- 2 don't use relative path to stylesheet or use a base tag. Try removing the leading dot in your paths to make them absolute – charlietfl Commented Sep 10, 2015 at 15:06
- ohhhh, thanx, writing <baser href='/'>) – Eugeniusz Zuev Commented Sep 10, 2015 at 15:17
2 Answers
Reset to default 3To fix this issue all you have to do is place the <base href="/">
element just below the <title>
element in the head section of index.html
page.
In my case, I was using packages installed by bower (the same should work for npm or yarn or any other package manager installed packages as well).
Add this middleware somewhere in your express code, before any other route declarations.
app.use('/assets', express.static(path.join(__dirname + '/bower_ponents')));
The first argument /assets
is just a virtual path that doesn't have to exist in your project, and the second one is telling express to serve static assets from the bower_ponents
folder.
Next, in your markup, have your stylesheet inclusions like the following:
<link rel="stylesheet" href="/assets/bulma/css/bulma.min.css">
本文标签:
版权声明:本文标题:javascript - Resource interpreted as Stylesheet but transferred with MIME type texthtml in AngularJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744817580a2626792.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论