我有帶組件路徑的角度應用程式
這是路由檔案
const routes: Routes = [
{ path: '', component: HomeComponent },
{
path: 'main',
children: [
{ path: 'faq', component: FaqComponent },
{ path: 'faq-mobile', component: FaqMobileComponent },
{ path: 'neighborhoods', component: NeighborhoodsComponent },
{ path: 'sales', component: SalesComponent },
{ path: 'commercials', component: CommercialsComponent },
{ path: 'rentals', component: RentalsComponent },
{ path: 'contact-us', component: ContactUsComponent },
{ path: 'list-with-us', component: ListWithUsComponent },
{ path: 'no-mobile', component: NoMobileComponent },
{ path: 'about-us', component: AboutUsComponent },
{ path: 'jobs', component: JobsComponent },
{ path: 'rooms', component: RoomsComponent },
{ path: 'join-the-hunt', component: JoinTheHuntComponent },
{ path: 'apply', component: ApplyMainComponent },
{ path: 'apply/:id', component: ApplyDetailsComponent },
{ path: 'home-mobile', component: HomeMobileComponent },
{ path: 'getting-approved', component: GettingApprovedComponent },
],
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule {}
例如,當我使用鏈接http://localhost:4200/main/apply并重繪 鏈接時,它會回傳給我http://localhost:4200
我怎樣才能讓它留在http://localhost:4200/main/apply?
uj5u.com熱心網友回復:
在我的角度專案中,我是這樣的:
{
path: '',
redirectTo: 'dashboard',
pathMatch: 'full'
}
--> 所以pathMatch: 'full'在這里添加可能會奏效。
uj5u.com熱心網友回復:
使用{ path: '', component: HomeComponent, pathMatch: 'full' }你的第一個路徑。當您重繪 時,您會被重定向到 HomeComponent,因為它是與您的路徑匹配的第一個路由。
看看:在 Angular 中,什么是“路徑匹配:完整”,它有什么作用?
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/326540.html
標籤:javascript 有角的 打字稿 angular2-routing
下一篇:迭代物件時如何斷言匹配型別?
