Skip to content

Commit

Permalink
Fix routing issue with removing query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
hachokbloomreach committed Nov 30, 2023
1 parent fe71180 commit bcd8b5b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
14 changes: 13 additions & 1 deletion brx-spartacus-storefront/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@
"maximumError": "5mb"
}
]
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production"
Expand All @@ -93,8 +101,12 @@
"configurations": {
"production": {
"browserTarget": "brx-spartacus:build:production"
},
"development": {
"browserTarget": "brx-spartacus:build:development"
}
}
},
"defaultConfiguration": "development"
},
"test": {
"builder": "@angular-builders/jest:run",
Expand Down
7 changes: 6 additions & 1 deletion brx-spartacus-storefront/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { NewsPageComponent } from './pages/news-page/news-page.component';
import { BrxComponent } from './brx/brx.component';

const routes: Routes = [{ path: 'news', component: NewsPageComponent }];
const routes: Routes = [
{ path: 'news', component: NewsPageComponent },
{ path: 'product/:productCode', component: BrxComponent },
{ path: '**', component: BrxComponent },
];

@NgModule({
imports: [
Expand Down
2 changes: 1 addition & 1 deletion brx-spartacus-storefront/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
limitations under the License.
-->

<brx-spartacus></brx-spartacus>
<router-outlet></router-outlet>
22 changes: 9 additions & 13 deletions brx-spartacus-storefront/src/app/brx/brx.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const ENDPOINT = new InjectionToken<string>('brXM API endpoint');
templateUrl: './brx.component.html',
styleUrls: ['./brx.component.scss'],
})
export class BrxComponent implements OnInit, OnDestroy {
export class BrxComponent implements OnDestroy {
configuration!: BrPageComponent['configuration'];

outletPosition = OutletPosition;
Expand Down Expand Up @@ -131,8 +131,6 @@ export class BrxComponent implements OnInit, OnDestroy {

pageContext$?: Observable<PageContext>;

private navigationEnd: Observable<NavigationEnd>;

showSpinner = true;

spinnerTimeout: any;
Expand All @@ -142,21 +140,19 @@ export class BrxComponent implements OnInit, OnDestroy {
private route: ActivatedRoute,
private routingService: RoutingService,
private envConfigService: EnvConfigService,
@Inject(ENDPOINT) endpoint?: string,
@Inject(REQUEST) @Optional() request?: Request,
) {
this.configuration = buildConfiguration(router.url, request, endpoint);
router.events.pipe(filter((event) => event instanceof NavigationEnd)).subscribe((navigationEvent) => {
const event = navigationEvent as NavigationEnd;
this.showSpinner = true;

this.navigationEnd = router.events.pipe(
filter((event) => event instanceof NavigationEnd),
) as Observable<NavigationEnd>;
}
this.endpointFromParams = this.route.snapshot.queryParamMap.get('endpoint') || undefined;
const endpoint: string = this.endpointFromParams
? this.endpointFromParams
: this.envConfigService.config.endpoint;

ngOnInit(): void {
this.navigationEnd.subscribe((event) => {
this.showSpinner = true;
this.configuration = buildConfiguration(event.url, request, endpoint);

this.configuration = { ...this.configuration, path: event.url };
this.brxHttpError = undefined;
this.pageContext$ = this.routingService
.getPageContext()
Expand Down
5 changes: 2 additions & 3 deletions brx-spartacus-storefront/src/app/brx/brx.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { BrSdkModule } from '@bloomreach/ng-sdk';
import { SpartacusModule } from '../spartacus/spartacus.module';
import { BrxComponent, ENDPOINT } from './brx.component';
import { BrxComponent } from './brx.component';
import { IsExternalLinkPipe } from './pipes/is-external-link.pipe';
import { IsInternalLinkPipe } from './pipes/is-internal-link.pipe';
import { ParseUrlPipe } from './pipes/parse-url.pipe';
import { FooterComponent } from './templates/footer/footer.component';
import { HeaderComponent } from './templates/header/header.component';
import { BrxPixelComponent } from './templates/brxpixel/brx-pixel.component';
import { environment } from '../../environments/environment';

@NgModule({
declarations: [
Expand All @@ -40,6 +39,6 @@ import { environment } from '../../environments/environment';
],
imports: [CommonModule, BrSdkModule, RouterModule, SpartacusModule],
exports: [BrxComponent],
providers: [{ provide: ENDPOINT, useValue: environment.libConfig.endpoint }],
providers: [],
})
export class BrxModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ export const environment = {
appConfig: {
defaultLoadingTime: 2, // in seconds
},
hasMultiTenantSupport: undefined,
hasMultiTenantSupport: 'true',
};

0 comments on commit bcd8b5b

Please sign in to comment.