Angular Url获取';s重置为上一个url

Angular Url获取';s重置为上一个url,angular,typescript,routes,Angular,Typescript,Routes,我正在创建一个角度应用程序,但我有一点视觉问题。 我有一个页面上有一个ReactiveForm,但每次我访问该页面时,url都会变回上一个url(尽管页面显示良好) 这是第一页: 然后我访问注册页面: 我确实看到了url的变化,但它立即又变了回来 app.module.ts: import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angular/core'; import {HttpM

我正在创建一个角度应用程序,但我有一点视觉问题。 我有一个页面上有一个
ReactiveForm
,但每次我访问该页面时,url都会变回上一个url(尽管页面显示良好)

这是第一页:

然后我访问注册页面:

我确实看到了url的变化,但它立即又变了回来

app.module.ts:

import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {HttpModule} from '@angular/http';
import {RouterModule, Routes} from "@angular/router";
import {InfiniteScrollModule} from "ngx-infinite-scroll";
import {ReactiveFormsModule} from "@angular/forms";

import {AppComponent} from './app.component';
import {NavComponent} from './nav/nav.component';
import {InformationComponent} from "./information/information.component";
import {PlacesComponent} from "./places/places.component";
import {LoginComponent} from './login/login.component';
import {NewsComponent} from './news/news.component';
import {NewsService} from "./news.service";
import {CreateNewsComponent} from './create-news/create-news.component';
import {RegisterFormComponent} from './register-form/register-form.component';

const appRoutes: Routes = [
  {
    path: '',
    component: InformationComponent
  },
  {
    path: 'plaatsen',
    component: PlacesComponent
  },
  {
    path: 'inloggen',
    component: LoginComponent
  }, {
    path: 'nieuws',
    component: NewsComponent
  }, {
    path: 'create-news',
    component: CreateNewsComponent
  }, {
    path: 'registreren',
    component: RegisterFormComponent
  }
];

@NgModule({
  declarations: [
    AppComponent,
    NavComponent,
    InformationComponent,
    PlacesComponent,
    LoginComponent,
    NewsComponent,
    CreateNewsComponent,
    RegisterFormComponent
  ],
  imports: [
    BrowserModule,
    ReactiveFormsModule,
    HttpModule,
    RouterModule.forRoot(appRoutes),
    InfiniteScrollModule
  ],
  providers: [
    NewsService
  ],
  bootstrap: [AppComponent]
})
export class AppModule {
}
register-form.component.ts:

import {Component, OnInit} from '@angular/core';
import {User} from '../_models/user';
import {FormBuilder, FormGroup, Validators} from "@angular/forms";

@Component({
  selector: 'app-register-form',
  templateUrl: './register-form.component.html'
})

export class RegisterFormComponent implements OnInit {
  registerForm: FormGroup;

  constructor(private fb: FormBuilder) {
  }

  ngOnInit(): void {
    this.buildForm();
  }

  user = new User(0, '', '', '', '', '');
  submitted = false;


  onSubmit() {
    this.submitted = true;
    this.user = this.registerForm.value;
  }

  onValueChanged(data?: any) {
    if (!this.registerForm) return;
    const form = this.registerForm;

    for (const field in this.formErrors) {
      this.formErrors[field] = '';
      const control = form.get(field);

      if (control && control.dirty && !control.valid) {
        const messages = this.validationMessages[field];
        for (const key in control.errors) {
          this.formErrors[field] += messages[key] + ' ';
          break; //To only show first error
        }
      }
    }
  }

  formErrors = {
    'email': '',
    'password': '',
    'password2': ''
  };

  validationMessages = {


  'email': {
'required': 'Email is required.',
  'email': 'This is not a valid e-mail address.'
}, 'password': {
  'required': 'Password can\'t be empty.',
  'minlength': 'Password must be at least 8 characters.'
}, 'password2': {
  'equal': 'Password\'s must be equal.'
}
  };

buildForm(): void {
this.registerForm = this.fb.group({
  'email': [this.user.email, [
    Validators.required,
    Validators.email
  ]],
  'password': [this.user.password, [
    Validators.required,
    Validators.minLength(8)
  ]],
  'password2': [this.user.password2]
});

this.registerForm.valueChanges.subscribe(data => this.onValueChanged(data));

this.onValueChanged();
}
}

多亏了@borislemke,我发现我的页面有一些错误,这就是为什么它出于某种原因更改了url(不过我很确定这是一个bug)。

多亏了@borislemke,我发现我的页面有一些错误,这就是为什么它出于某种原因更改了url(不过我很确定这是个bug).

控制台是否显示任何错误?哦,是的,它有一些错误,这就是原因…控制台是否显示任何错误?哦,是的,它有一些错误,这就是原因。。。