繁体   English   中英

以角度 4 配置 url 路径

[英]Configure url path in angular 4

您好,感谢您花时间阅读本文。 我正在尝试为基本应用程序配置 url,但我无法弄清楚这是在何处完成的。

我想称之为路由,但我知道这不是正确的词,所以让我对我正在尝试做的事情做一些解释。 我们得到了一个 MVC 应用程序的模板,它允许我们将 angular 2 添加到应用程序中,在 Visual Studio 中运行良好,我们在 IIS 中部署到它自己的网站,它可以工作。 我们将其移至不再工作的默认网站。

说了这么多,现在我可以解释问题是什么了,浏览器正在访问localhost/Test/上的应用程序,但是当它尝试下载app.component.ts所有其他应用程序时,它会尝试转到localhost/app/app.component.js不是localhost/Test/app/app.component 现在我的问题是:我在哪里配置 url 以转到 localhost。 测试/应用程序...?

import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { LoginComponent } from './components/login/login.component';
import { GenerateComponent } from './components/generate/generate.component';
import { NewuserComponent } from './components/newuser/newuser.component';
import { NewlocationComponent } from './components/newlocation/newlocation.component';

const appRoutes: Routes = [
    { path: '', redirectTo: 'login', pathMatch: 'full' },
    { path: 'login', component: LoginComponent },
    { path: 'generate', component: GenerateComponent },
    { path: 'newuser', component: NewuserComponent },
    { path: 'newlocation', component: NewlocationComponent }
];

export const routing: ModuleWithProviders =
    RouterModule.forRoot(appRoutes);

您需要在 angular-cli 上设置deploy-url选项。

检查文档

你可以这样做

对于serve命令ng serve --deploy-url /test/

对于build命令ng build --deploy-url /test/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM