Angular 7已完全重新加载到同一URL

时间:2019-04-03 15:18:02

标签: angular angular-routing

我有此代码:

onSubmit(search: string, from: string, to: string) {
        this.router.navigate(['/recherche'], {
          queryParams: {
            search: search,
            from: from,
            to: to
          }
        });
      }

此视图:

       <form ngNoForm>
          <div class="row">
            <div class="col-11">
              <input #search id="search" name="search" class="form-control form-control-lg w-100" type="text" />
            </div>
            <div class="col-1">
              <button (click)="onSubmit(search.value, from.value, to.value);" class="btn btn-lg btn-black" type="submit"><i class="fa fa-search"></i></button>
            </div>
          </div>

这就是我在结果页面上获取参数的方式:

    constructor(
        private route: ActivatedRoute,
        private eventService: EventService,
        private locationService: LocationService,
      ) {});
      }

  ngOnInit() {
    // Subscribe to query parameters
    this.route.queryParamMap.subscribe(queryParams => {
      // Retreive the parameters
      let search = queryParams.get('search').trim();
      let from = queryParams.get('from');
      let to = queryParams.get('to');

      // List the events
      this.listEvents(search, from, to);

      // List the locations
      this.listLocations(search);
    });
  }

当我第一次搜索时,一切进展顺利。如果我进行了第二次搜索,则该应用程序已完全重新加载。我想念什么?

路由模块代码部分:

{ 
    path: 'recherche',
    component: SearchComponent
  },

准确地说,仅当我在/recherche路径上时,应用才会重新加载。如果我在执行第二次搜索之前移到另一台路由器,则它可以工作。

0 个答案:

没有答案