离开后如何摆脱角度2上的网页中的页面

时间:2017-09-20 14:08:24

标签: angular angular2-routing

好的,让我解释一下,让它易于理解

基本上我必须路线

  • 本地主机:5555 /查找
  • 本地主机:5555 /产品名称-的productId

当我前往 / 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>

0 个答案:

没有答案