[英]angular routing from static page / URL
Angular 5(修訂版)
經過一晚上的閱讀和測試並嘗試了不同的方法之后,我已經提煉了我的問題。
問題變成了,如何從應用程序外導航到我的角度應用程序中的路徑。
我得到相同的結果-鍵入並通過href鏈接到除應用程序根目錄以外的任何其他路徑,會導致該應用程序包括公共html
這是我能想到的最簡單的方案。
dist
|- members
|- index.html
其中“成員”是有角度的應用程序的根-在中指定(我嘗試過並沒有什么不同)
/index.html(稱為主頁)看起來像這樣
<a href="members/login" >login</a>
<a href="members/register" >register</a>
應用路由器看起來像這樣
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { RegisterComponent } from './components/register/register.component';
import { LoginComponent } from './components/login/login.component';
const appRoutes: Routes = [
{ path: '', component: LoginComponent, pathMatch: 'full' },
{ path: 'register', component: RegisterComponent, pathMatch: 'full' },
{ path: 'login', component: LoginComponent, pathMatch: 'full' }
{ path: '**', redirectTo: 'members/login' }
];
@NgModule({
imports: [
RouterModule.forRoot( appRoutes )
],
exports: [
RouterModule
]
})
export class AppRoutingModule {}
我的4種情況1)輸入“ localhost / index.html”-給我(主頁)鏈接2)單擊任一鏈接-給我(主頁)3)在地址欄中輸入“ localhost / members / login”或“ localhost / members / register”-給我(主頁)鏈接4)在地址欄中輸入“ localhost / members”-給我該應用程序
我缺少有關路由的信息...無法解決。 我希望我重提這個問題,並得到答案-
幫助請謝謝
嘗試pathMatch:'full'
作為默認組件
const appRoutes: Routes = [
{ path: '', component: ProfileComponent, pathMatch:'full' },
{ path: 'register', component: RegisterComponent },
{ path: 'login', component: LoginComponent },
...
{ path: '**', redirectTo: '/login' }
];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.