小编Chr*_*ris的帖子

路由始终重新加载页面

当我使用从1个组件到下一个组件的路径进行导航时,angular总是重新加载应用程序.活动顺序:

  • 加载主页(locahost:4200)
  • 重定向到位置(localhost:4200/locations)
  • 点击按钮路线到(localhost:4200/items/1)
  • 显示项目页面
  • 然后它自动路由到(localhost:4200 /#)[怎么能阻止它这样做?]
  • 然后它路由回到位置(localhost:4200/locations)

关于什么是错的想法以及为什么它不停在项目页面上?我一直在拉我的头发(剩下的东西)试图找出一些我确定是一个简单的用户错误的东西.

此外,Chrome控制台或webstorm终端中没有错误.我正在使用角度4.2.4.

这是我的组件:

的AppModule

import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';

import {AppComponent} from './app.component';
import {LocationComponent } from './location/location.component';
import {ItemsComponent } from './items/items.component';

import {AppRoutingModule} from './app-routing.module';

@NgModule({
  imports: [
    BrowserModule,
    FormsModule,
    AppRoutingModule
  ],
  declarations: [
    AppComponent,
    LocationComponent,
    ItemsComponent
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)

AppRouting

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import …
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular

7
推荐指数
2
解决办法
7484
查看次数

标签 统计

angular ×1

angular2-routing ×1