angular2 - 当URL包含查询参数时,无法匹配任何路由

时间:2017-01-10 18:03:41

标签: angular angular2-routing

我正在尝试使用确认令牌链接到确认电子邮件网址,但在包含查询参数时,angular2拒绝解析该网址。

网址如下所示:http://localhost:4200/account/confirm-email;userid=33174f7d-0ca9-4770-86d1-4ec04e53062e;token=qLkA+g/5rquoPC16+fRLx7sbVvz061tKiwTKm5Yd/lghA6vRPkDLm4/93JdQkaPIlrZbrPrBNwM3h5PSpObHTA2tF6bbGCJD3IiFwQaPNc2NT5ekDIrVmfV1RzTGfzJUZcrtErTfkA2ypUc1AWc5LLdYZjF0KYwTsg0S+jQ2UJgOwU9J5uNHZURrwfvvriIW

这是我的路由器app-routing.module.ts

const routes: Routes = [
  {
    path: '',
    redirectTo: '/dashboard',
    pathMatch: 'full'
  },
  {
    path: 'dashboard',
    loadChildren: 'app/+dashboard/dashboard.module#DashboardModule'
  },
  {
    path: 'media',
    loadChildren: 'app/+media/media.module#MediaModule',
    canActivate: [AuthGuard]
  },
  {
    path: 'location',
    loadChildren: 'app/+location/location.module#LocationModule',
    canActivate: [AuthGuard]
  },
  {
    path: 'login',
    loadChildren: 'app/+login/login.module#LoginModule'
  },
  {
    path: 'account',
    loadChildren: 'app/+account/account.module#AccountModule'
  },
  {
    path: 'register',
    redirectTo: '/account/register'
  },
  {
    path: 'unauthorized',
    component: UnauthorizedComponent
  },
  // {
  //   path: '**',
  //   redirectTo: '/dashboard'
  // }
];

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

这是帐户模块的路由配置:

export const routes: Routes = [
  {
    path: '',
    component: AccountComponent
  },
  {
    path: 'register',
    component: RegisterComponent
  },
  {
    path: 'confirm-email',
    component: ConfirmEmailComponent
  },
  {
    path: 'finish-registration',
    component: FinishRegistrationComponent
  }
];

@NgModule({
  imports: [
    RouterModule.forChild(routes)
  ],
  exports: [],
  providers: []
})
export class AccountRoutingModule {}

当我使用此URL调用应用程序时,路径匹配有效,但所有查询参数都未定义:http://localhost:4200/account/confirm-email?userid=33174f7d-0ca9-4770-86d1-4ec04e53062e;token=qLkA+g/5rquoPC16+fRLx7sbVvz061tKiwTKm5Yd/lghA6vRPkDLm4/93JdQkaPIlrZbrPrBNwM3h5PSpObHTA2tF6bbGCJD3IiFwQaPNc2NT5ekDIrVmfV1RzTGfzJUZcrtErTfkA2ypUc1AWc5LLdYZjF0KYwTsg0S+jQ2UJgOwU9J5uNHZURrwfvvriIW

如何配置路由以使其正常工作?

0 个答案:

没有答案