I have an app with 3 routes:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SearchComponent } from './pages/search/search.component';
import { CreateUserComponent } from './pages/create-user/create-user.component';
import { UserProfileComponent } from './pages/user/user-profile.component';
const routes: Routes = [
{
path: '',
redirectTo: 'search',
pathMatch: 'full'
},
{
path: 'search',
component: SearchComponent,
data: {
breadcrumb: 'Search'
}
},
{
path: 'create-user',
component: CreateUserComponent,
data: {
breadcrumb: 'Create User'
}
},
{
path: 'user/:auth0Id',
component: UserProfileComponent,
data: {
breadcrumb: 'Profile'
}
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class UserManagementRoutingModule { }
In the SearchComponent template, I have a button that make a GET request when clicked:
search.component.html
<button nz-button nzType="primary" type="button"
(click)="searchAll()">{{ 'SEARCH.SEARCH-FORM.SEARCH-ALL-BTN' | translate }}</button>
search.component.ts
searchAll(): void {
this.tableLoadingText = 'SEARCH.RESULT.LOADING-SEARCH';
this.isTableLoading = true;
this.currentSearchType = 'searchAll';
this.scimB2bService.getAllUsers(this.pageSize, this.pageIndex).subscribe((res: IB2bScimUserList) => {
this.userList = res.Resources;
this.totalUser = res.totalResults;
this.mapUsers(this.userList);
this.triggerFeedback('success', 'SEARCH.STATUS.SUCCESS.SEARCH-ALL', null);
}, error => {
this.isTableLoading = false;
this.triggerFeedback('error', 'SEARCH.STATUS.ERROR.SEARCH-ALL', error);
});
}
What's the easiest way to go to 'user/:auth0Id' route and comme back to 'search' route without loosing the search results (I mean not having to do the GET request again)?
Thanks!