diff --git a/cypress/integration/dashboard.spec.ts b/cypress/integration/dashboard.spec.ts index 80c6c1f8..8ecb9c98 100644 --- a/cypress/integration/dashboard.spec.ts +++ b/cypress/integration/dashboard.spec.ts @@ -175,7 +175,7 @@ describe('dashboard', async function () { .find('.searchbar') .type('test', {scrollBehavior: false}) .type('{enter}', {scrollBehavior: false}); - cy.url().should('eq', Cypress.config().baseUrl + '/search/test'); + cy.url().should('eq', Cypress.config().baseUrl + '/search?query=test'); cy.get('ion-searchbar').should('have.value', 'test'); cy.get('stapps-data-list-item').should('have.length.greaterThan', 0); @@ -185,7 +185,7 @@ describe('dashboard', async function () { cy.visit('/overview'); cy.get('stapps-search-section').find('ion-icon[name=search]').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/search/'); + cy.url().should('eq', Cypress.config().baseUrl + '/search?query='); cy.get('ion-searchbar').should('not.have.value'); cy.get('stapps-data-list-item').should('have.length', 0); diff --git a/src/app/modules/dashboard/sections/search-section/search-section.component.ts b/src/app/modules/dashboard/sections/search-section/search-section.component.ts index 522eebc6..3c0d111d 100644 --- a/src/app/modules/dashboard/sections/search-section/search-section.component.ts +++ b/src/app/modules/dashboard/sections/search-section/search-section.component.ts @@ -35,7 +35,7 @@ export class SearchSectionComponent { */ onSubmitSearch() { this.router - .navigate(['/search', this.searchTerm]) + .navigate(['/search'], {queryParams: {query: this.searchTerm}}) .then(() => this.hideKeyboard()); } diff --git a/src/app/modules/data/data-routing.module.ts b/src/app/modules/data/data-routing.module.ts index 178def4b..6ca16a5d 100644 --- a/src/app/modules/data/data-routing.module.ts +++ b/src/app/modules/data/data-routing.module.ts @@ -1,16 +1,16 @@ /* * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . */ import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; @@ -20,7 +20,6 @@ import {SearchPageComponent} from './list/search-page.component'; const dataRoutes: Routes = [ {path: 'search', component: SearchPageComponent}, - {path: 'search/:term', component: SearchPageComponent}, {path: 'data-detail/:uid', component: DataDetailComponent}, {path: 'canteen', component: FoodDataListComponent}, ]; diff --git a/src/app/modules/data/list/search-page.component.ts b/src/app/modules/data/list/search-page.component.ts index e5682d0a..e901247a 100644 --- a/src/app/modules/data/list/search-page.component.ts +++ b/src/app/modules/data/list/search-page.component.ts @@ -277,6 +277,11 @@ export class SearchPageComponent implements OnInit, OnDestroy { * Search event of search bar */ searchStringChanged(queryValue: string) { + this.router.navigate([], { + relativeTo: this.route, + queryParams: {query: queryValue}, + queryParamsHandling: 'merge', + }); this.queryTextChanged.next(queryValue); } @@ -366,7 +371,7 @@ export class SearchPageComponent implements OnInit, OnDestroy { * Initialize */ async ionViewWillEnter() { - const term = this.route.snapshot.paramMap.get('term') || undefined; + const term = this.route.snapshot.queryParamMap.get('query') || undefined; if (term) { this.queryText = term; this.searchStringChanged(term); diff --git a/src/app/modules/data/list/search-page.html b/src/app/modules/data/list/search-page.html index 201f28cd..c5577f90 100644 --- a/src/app/modules/data/list/search-page.html +++ b/src/app/modules/data/list/search-page.html @@ -49,8 +49,8 @@ 'search.type' | translate }}