gpt4 book ai didi

angular - 在子目录中运行 Angular2

转载 作者:太空狗 更新时间:2023-10-29 16:53:15 24 4
gpt4 key购买 nike

我有一个在本地主机下运行良好的应用程序。

我今天试图将其作为子应用程序发布到 IIS 服务器上。因此新路径将是 localhost/SubDir。

System.js 现在到处都在尝试加载模块。我设置了 basePath 并使用路径/ map 配置变量玩了几个小时,但无法进入神奇的设置。

有没有人知道我想调整什么,或者任何有助于调试的东西?

Chrome 控制台 enter image description here

Chrome 网络 enter image description here

索引 HTML

<html>
<head>
<script src="~/node_modules/es6-shim/es6-shim.js"></script>
<script src="~/node_modules/systemjs/dist/system.src.js"></script>
<script src="~/node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="~/node_modules/angular2/bundles/http.dev.js"></script>
<script src="~/node_modules/angular2/bundles/router.dev.js"></script>

<link href="~/node_modules/bootstrap/dist/css/bootstrap.css" rel="stylesheet" />

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->

<link href="~/assets/css/site.css" rel="stylesheet" />

<script>
System.config({
packages: { 'app': { defaultExtension: 'js' } },
baseURL: '/MedicheckAngular/',
paths: {
//'angular2/*': 'node_modules/angular2/ts/*.js'
}
});

System.import('app/app');
</script>

</head>
<body>
<my-app>loading...</my-app>
</body>
</html>

和应用入口点

import {HTTP_PROVIDERS} from 'angular2/http';
import {bootstrap, bind, provide} from 'angular2/angular2';
import {RouteConfig, RouteParams, ROUTER_DIRECTIVES, APP_BASE_HREF, ROUTER_BINDINGS, LocationStrategy, PathLocationStrategy, HashLocationStrategy} from 'angular2/router';

import {AppLayout} from './components/app-layout/app-layout';


bootstrap(AppLayout, [
ROUTER_BINDINGS,
HTTP_PROVIDERS,
provide(APP_BASE_HREF, {useValue:'/'}),
provide(LocationStrategy, { useClass: HashLocationStrategy })
]);

应用文件夹结构

enter image description here

最佳答案

要在 apache 的子目录中托管,您可以这样做:

构建命令类似于:ng build --base-href/myapp/

.htaccess 文件看起来像这样

RewriteEngine On
RewriteBase /myapp/
Options +FollowSymLinks

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.html [L,QSA]

关于angular - 在子目录中运行 Angular2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34010970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com