[英]Angular: HTML5 style URL is rendering with no stylesheet
I turned on HTML5 style URLs (no '#') in Angular like this: 我在Angular中打开了HTML5样式的URL(没有'#'),如下所示:
$locationProvider.html5Mode({
enabled: true,
requireBase: true
});
And added a base tag: 并添加了一个基本标签:
<base href="/">
Now when I navigate to http://profile.myapp.com/show/1234
it renders the page without any styles applied. 现在,当我导航到
http://profile.myapp.com/show/1234
它将呈现未应用任何样式的页面。
However when I use the URL with a '#' the page renders correctly. 但是,当我将URL与“#”一起使用时,页面将正确呈现。 Similarly, if I disable HTML5 style URLs, the page renders correctly.
同样,如果禁用HTML5样式的URL,则页面将正确呈现。
I'm using ui-router, configured with: 我正在使用ui-router,配置为:
/** @ngInject */
function routerConfig($stateProvider, $urlRouterProvider) {
$stateProvider
.state('showProfile', {
url: '/show/:id',
templateUrl: 'app/profile/profile.html',
controller: 'ProfileController',
controllerAs: 'profileController'
});
$urlRouterProvider.otherwise('/show/1234');
}
CSS Injected via Gulp Task: 通过Gulp任务注入的CSS:
The CSS is injected via the Gulp task from this Yeoman Generator . CSS是通过Gulp任务从这个Yeoman Generator注入的。
<!-- build:css({.tmp/serve,src}) styles/app.css -->
<!-- inject:css -->
<link rel="stylesheet" href="app/index.css">
<!-- endinject -->
<!-- endbuild -->
The task looks something like: 该任务看起来像:
var injectFiles = gulp.src([ path.join(conf.paths.src, '/app/**/*.scss'), path.join('!' + conf.paths.src, '/app/index.scss') ], { read: false }); var injectFiles = gulp.src([path.join(conf.paths.src,'/app/**/*.scss'),path.join('!'+ conf.paths.src,'/ app / index .scss')],{阅读:false});
var injectOptions = {
transform: function(filePath) {
filePath = filePath.replace(conf.paths.src + '/app/', '');
return '@import "' + filePath + '";';
},
starttag: '// injector',
endtag: '// endinjector',
addRootSlash: false
};
Question: 题:
Why does this happen, and is there something I can do to fix it, other than not using HTML5 style URLs? 为什么会发生这种情况,除了不使用HTML5样式的URL之外,我还能做些什么来解决它?
通过将基本标记<base href="/">
从主体移到头部,似乎已解决了该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.