好的,让我解释一下,让它易于理解
基本上我必须路线
当我前往 / find 路线并点击任何产品时,它会转到 productName-productId ,但会显示在网址localhost:5555/find/xxxxxxxxx-xxxxx
上
它运作良好,但我需要删除网址中的/find
,只需localhost:5555/productName-Id
item.component.html
我一直试图摆脱它,但它显示find
<a [routerLink]="[getTitleUrl(data.details.model, data.details.make ), whip.id ]">
.....
</a>
item.component.ts
getTitleUrl(make, model ): string{
//convert spaces into -
var make = make.replace(/\s+/g, '-').toLowerCase();
var model = model.replace(/\s+/g, '-').toLowerCase();
//concat
let title = model +'-'+ make;
return '../'+ title ; // adding '../' solved the problem
}
主-routing.module.html
...
@NgModule({
imports: [
RouterModule.forChild([
{ path: 'find', component: FindItemComponent},
{ path: ':title-:id', component: ItemDetailComponent },
{ path: 'signin', component: SigninComponent, canActivate: [AuthGuard] },
{ path: 'signup', component: SignupComponent, canActivate: [AuthGuard] },
{ path: '**', component: HomeComponent }
])
]
})
...
find.component.html
<app-item *ngFor="let item of items| slice:0:15| truncate; let i=index"></app-item>