Angular2不会重定向到页面,请更改URL但不要加载页面

时间:2018-08-01 19:00:31

标签: angular angular-ui-router

我正在使用Angular2和路线,因此,当我单击链接时,URL更改但正文没有更改
这是我的路线

import { Routes} from '@angular/router';
//Import components
import { NewComponent } from './new/new.component';
import { ShowComponent } from './show/show.component';
import { FunnelsComponent } from './funnels.component';

export const FUNNELS_ROUTES: Routes = [
{   path: 'newfunnel',
    component: NewComponent
},
{   path: 'showfunnel',
    component: ShowComponent
},
{
  path:'funnels',
  component: FunnelsComponent
},
{path: '**', pathMatch: 'full', redirectTo: 'funnels'}
];

我就这样使用

<a [routerLink]="['showfunnel']">
   <img src="assets/img/ic-vistaprevia.png" class="vista">
</a>
----------------------------------------------------
<a [routerLink]="['newfunnel']">New Funnel</a>

this is my directory tree

那么,有人可以帮助我找到我的错误吗?

1 个答案:

答案 0 :(得分:0)

  

检查一下可能有帮助

import { NgModule } from '@angular/core';
    import { RouterModule, Routes } from '@angular/router';
    import { NewComponent } from './new/new.component';
    import { ShowComponent } from './show/show.component';
    import { FunnelsComponent } from './funnels.component';



    const routes: Routes = [
      { path: '', redirectTo: 'funnels', pathMatch: 'full'},
      { path: 'newfunnel', component: NewComponent},
      { path: 'showfunnel', component: ShowComponent },
      { path: 'funnels', component: FunnelsComponent }

    ];



    @NgModule({
      imports:[
        RouterModule.forRoot(routes)
      ],
      exports: [ RouterModule ]
    })
    export class AppRoutingModule { // export class

    }
  

HTML

<a routerLink="/showfunnel">
   <img src="assets/img/ic-vistaprevia.png" class="vista">
</a>
<a routerLink="/newfunnel">New Funnel</a>