Skip to content

Commit 66f7c2a

Browse files
Fixed bug where navigating to a URL that is a partial match to the current base URL attempted in-SPA navigation (blackbaud#372)
Fixes blackbaud/skyux2#1559
1 parent f47c0fa commit 66f7c2a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/app/app.component.spec.ts

+21
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ describe('AppComponent', () => {
200200
};
201201
scrollCalled = false;
202202
viewport = new SkyAppViewportService();
203+
navigateByUrlParams = undefined;
203204
});
204205

205206
it('should create component', async(() => {
@@ -576,6 +577,26 @@ describe('AppComponent', () => {
576577
});
577578
}));
578579

580+
it('should handle global links that start with the same base URL as the SPA', async(() => {
581+
let spyOmnibar = spyOn(BBOmnibar, 'load');
582+
583+
skyAppConfig.skyux.omnibar = {
584+
experimental: true
585+
};
586+
587+
skyAppConfig.skyux.host.url = 'base.com/';
588+
skyAppConfig.runtime.app.base = 'custom-base/';
589+
590+
setup(skyAppConfig, false).then(() => {
591+
fixture.detectChanges();
592+
const cb = spyOmnibar.calls.first().args[0].nav.beforeNavCallback;
593+
594+
let globalLink = cb({ url: 'base.com/custom-base-2' });
595+
expect(globalLink).toEqual(true);
596+
expect(navigateByUrlParams).not.toBeDefined();
597+
});
598+
}));
599+
579600
it('should use the original url casing if calling navigateByUrl', async(() => {
580601
let spyOmnibar = spyOn(BBOmnibar, 'load');
581602

src/app/app.component.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,13 @@ export class AppComponent implements OnInit {
158158
nav.beforeNavCallback = (item: BBOmnibarNavigationItem) => {
159159
const url = item.url.toLowerCase();
160160

161-
if (url.indexOf(baseUrl) === 0) {
161+
if (
162+
url === baseUrl ||
163+
// Make sure the base URL is not simply a partial match of the base URL plus additional
164+
// characters after the base URL that are not "terminating" characters
165+
url.indexOf(baseUrl + '/') === 0 ||
166+
url.indexOf(baseUrl + '?') === 0
167+
) {
162168
const routePath = item.url.substring(baseUrl.length, url.length);
163169

164170
// Since the omnibar is loaded outside Angular, navigating needs to be explicitly

0 commit comments

Comments
 (0)