簡體   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