[英]Configure url path in angular 4
Hello and thank you for taking the time to read this.您好,感谢您花时间阅读本文。 I am trying to configure the url for the base application, and I just cannot figure out where this is done at.
我正在尝试为基本应用程序配置 url,但我无法弄清楚这是在何处完成的。
I want to call it Routing, but I know that this isn't the correct words, so let me do a bit of explanation on what I'm trying to do.我想称之为路由,但我知道这不是正确的词,所以让我对我正在尝试做的事情做一些解释。 We got a template for an MVC application that allowed us to add angular 2 into the app, works great from Visual Studio, we deploy in IIS into its own web site it works.
我们得到了一个 MVC 应用程序的模板,它允许我们将 angular 2 添加到应用程序中,在 Visual Studio 中运行良好,我们在 IIS 中部署到它自己的网站,它可以工作。 We move it to the default website it no longer works.
我们将其移至不再工作的默认网站。
With all of that said now I can explain what the issue is, the browser is getting to the application at localhost/Test/
but when it is trying to download the app.component.ts
all of the others, it then is trying to goto localhost/app/app.component.js
not localhost/Test/app/app.component
.说了这么多,现在我可以解释问题是什么了,浏览器正在访问
localhost/Test/
上的应用程序,但是当它尝试下载app.component.ts
所有其他应用程序时,它会尝试转到localhost/app/app.component.js
不是localhost/Test/app/app.component
。 Now my questions: where do i configure the url to go to localhost.现在我的问题是:我在哪里配置 url 以转到 localhost。 Test /app...?
测试/应用程序...?
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);
You need to set deploy-url
option on angular-cli.您需要在 angular-cli 上设置
deploy-url
选项。
You can do it as follows你可以这样做
For serve
command ng serve --deploy-url /test/
对于
serve
命令ng serve --deploy-url /test/
For build
command ng build --deploy-url /test/
对于
build
命令ng build --deploy-url /test/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.