diff --git a/packages/history-service/src/__tests__/create-root-location-transformer.test.ts b/packages/history-service/src/__tests__/create-root-location-transformer.test.ts index 9aeb3578..75b85592 100644 --- a/packages/history-service/src/__tests__/create-root-location-transformer.test.ts +++ b/packages/history-service/src/__tests__/create-root-location-transformer.test.ts @@ -116,7 +116,7 @@ describe('#createRootLocationTransformer', () => { describe('#getConsumerPathFromRootLocation', () => { describe('with consumers encoded into the query parameter', () => { - it('returns the consumer-specific locations', () => { + it('returns the consumer-specific locations including a hash for the primary consumer', () => { const locationTransformer = createRootLocationTransformer({ consumerPathsQueryParamName: '---', primaryConsumerHistoryKey: 'testPri' @@ -124,7 +124,8 @@ describe('#createRootLocationTransformer', () => { const rootLocation = { pathname: '/foo', - search: `?bar=1&---=${encodeConsumerPaths({test1: '/baz?qux=3'})}` + search: `?bar=1&---=${encodeConsumerPaths({test1: '/baz?qux=3'})}`, + hash: '#some-anchor' }; expect( @@ -132,7 +133,7 @@ describe('#createRootLocationTransformer', () => { rootLocation as Location, 'testPri' ) - ).toEqual('/foo?bar=1'); + ).toEqual('/foo?bar=1#some-anchor'); expect( locationTransformer.getConsumerPathFromRootLocation( diff --git a/packages/history-service/src/__tests__/index.test.ts b/packages/history-service/src/__tests__/index.test.ts index 9a5dca92..05193ab3 100644 --- a/packages/history-service/src/__tests__/index.test.ts +++ b/packages/history-service/src/__tests__/index.test.ts @@ -198,7 +198,7 @@ describe('defineHistoryService', () => { destroyHistories(); const consumerStates = {test1: 'foo state', test2: 'bar state'}; - const url = createUrl({test1: '/foo', test2: 'bar'}); + const url = createUrl({test1: '/foo#some-anchor', test2: 'bar'}); window.history.pushState({state: consumerStates}, '', url); @@ -206,7 +206,8 @@ describe('defineHistoryService', () => { expect(history1.location).toMatchObject({ pathname: '/foo', - state: 'foo state' + state: 'foo state', + hash: '#some-anchor' }); expect(history2.location).toMatchObject({ diff --git a/packages/history-service/src/create-root-location-transformer.ts b/packages/history-service/src/create-root-location-transformer.ts index 86a0743d..471de197 100644 --- a/packages/history-service/src/create-root-location-transformer.ts +++ b/packages/history-service/src/create-root-location-transformer.ts @@ -154,10 +154,10 @@ export function createRootLocationTransformer( if (isPrimaryConsumer) { searchParams.delete(consumerPathsQueryParamName); - const pathname = rootLocation.pathname; + const {pathname, hash} = rootLocation; const search = serializeSearchParams(searchParams); - return history.createPath({pathname, search}); + return history.createPath({pathname, search, hash}); } const consumerPaths = searchParams.get(consumerPathsQueryParamName);