【问题标题】:Angular 4 router loading all the componentsAngular 4 路由器加载所有组件
【发布时间】:2018-02-08 08:58:33
【问题描述】:

我目前正在使用 Angular 4 开发一个项目。直到今天,我在使用 Router 时还没有遇到任何问题,但我使用了 Angular Materials 组件,今天早上我看到我必须更新 Angular Material 包。我执行了:

npm update

从那时起,当我使用 RouterLink 时,组件就会加载到实际页面的顶部。例如,如果我在“/dashboard”中并且我想转到“/signin”页面。 “登录”组件加载在仪表板顶部,因此在同一页面中,我有仪表板组件登录组件。

你有什么想法可以帮我解决这个问题吗?

编辑:

我的组件不再响应,如果我使用带有在我的组件中定义的数组的 *ngFor,如果数组更改了带有 *ngFor 的组件不会改变...我认为我所有的问题都是相关的,但是我看不出来。

我如何使用 RouterLink :

<a md-tab-link routerLink="/login" routerLinkActive="active">Login</a>

我的 app.routing.module.ts 的代码:

    import { NgModule }             from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { SentierDetailComponent } from './map/sentier/sentier-detail.component'
import { DashboardComponent }   from './dashboard/dashboard.component';
import { LoginComponent } from './login/login.component';
import { SignInComponent } from './signin/signin.component';
import { MembreComponent } from './membre/membre.component'
import { FormComponent } from './form.component'

const routes: Routes = [
    { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
    { path: 'dashboard',  component: DashboardComponent },
    { path: 'login', component: LoginComponent},
    { path: 'signin', component: SignInComponent},
    { path: 'sentier-detail/:id', component: SentierDetailComponent},
    { path: 'membres', component: MembreComponent},
    { path:'evenement', component: FormComponent}
];

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

【问题讨论】:

  • 请提供更多关于您如何使用RouterLink的信息(例如代码示例)
  • 请提供您如何配置RouterModule

标签: angular router routerlink angular4-router routerlinkactive


【解决方案1】:

好吧,错误似乎来自文件 app.module.ts。我从我的项目的旧版本中获取了它的旧版本,现在一切都很好,但我仍然不知道这个错误的确切来源。

【讨论】:

    猜你喜欢
    • 2019-01-14
    • 2017-10-05
    • 2018-05-29
    • 1970-01-01
    • 2018-04-30
    • 2017-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多