Router Selectors
- getRouterStack
- getCurrentRoute
- getCurrentParams
- getCurrentPathname
- getCurrentQuery
- getCurrentSearchQuery
- getCurrentState
getRouterStack
Retrieves the router stack from the store.
Usage
import { getRouterStack } from '@shopgate/engage/core';
Attention: The path to the old modules is deprecated and will be removed in ENGAGE v7:
import { getRouterStack } from '@shopgate/pwa-common/selectors/router';
Returns
(Array|[]): The current router stack. If the stack is empty, it returns []
.
Example Result
[{
id: 'juicb',
pattern: '/',
pathname: '/',
location: '/',
params: {},
query: {},
hash: null,
state: {},
created: 1562587961638,
updated: 1562588028967,
}, {
id: 'sb5tk',
pattern: '/category/:categoryId',
pathname: '/category/3637',
location: '/category/3637?sort=priceAsc#some-hash',
params: {
categoryId: '3637'
},
query: {
sort: 'priceAsc'
},
state: {
title: 'My Page Title'
},
hash: 'some-hash',
created: 1562587961738,
updated: 1562588029967,
}]
getCurrentRoute
Retrieves the current visible route from the store.
Usage
import { getCurrentRoute } from '@shopgate/engage/core';
Attention: The path to the old modules is deprecated and will be removed in ENGAGE v7:
import { getCurrentRoute } from '@shopgate/pwa-common/selectors/router';
Parameters
state
(Object) required: The application state.props
(Object) : An object containing props.routeId
(string): Can be passed to select a specific route from the stack.
Returns
(Object|null): The route object. If nothing was found, it returns null
.
Example Data
{
id: 'sb5tk',
pattern: '/category/:categoryId',
pathname: '/category/3637',
location: '/category/3637?sort=priceAsc#some-hash',
params: {
categoryId: '3637'
},
query: {
sort: 'priceAsc'
},
state: {
title: 'My Page Title'
},
hash: 'some-hash',
created: 1562587961738,
updated: 1562588029967,
}
getCurrentParams
Retrieves the params of the current visible route from the store.
Usage
import { getCurrentParams } from '@shopgate/engage/core';
Attention: The path to the old modules is deprecated and will be removed in ENGAGE v7:
import { getCurrentParams } from '@shopgate/pwa-common/selectors/router';
Parameters
state
(Object) required: The application state.props
(Object) : An object containing props.routeId
(string): Can be passed to select a specific route from the stack.
Returns
(Object|null): The params object. If nothing was found, it returns null
.
getCurrentPathname
Retrieves the pathname of the current visible route from the store.
Usage
import { getCurrentPathname } from '@shopgate/engage/core';
Attention: The path to the old modules is deprecated and will be removed in ENGAGE v7:
import { getCurrentPathname } from '@shopgate/pwa-common/selectors/router';
Parameters
state
(Object) required: The application state.props
(Object) : An object containing props.routeId
(string): Can be passed to select a specific route from the stack.
Returns
(string|null): The pathname. If nothing was found, it returns null
.
getCurrentQuery
Retrieves the query of the current visible route from the store.
Usage
import { getCurrentQuery } from '@shopgate/engage/core';
Attention: The path to the old modules is deprecated and will be removed in ENGAGE v7:
import { getCurrentQuery } from '@shopgate/pwa-common/selectors/router';
Parameters
state
(Object) required: The application state.props
(Object) : An object containing props.routeId
(string): Can be passed to select a specific route from the stack.
Returns
(Object|null): The query. If nothing was found, it returns null
.
getCurrentSearchQuery
Retrieves the search query (query parameter āsā) of the current visible route from the store.
Usage
import { getCurrentSearchQuery } from '@shopgate/engage/core';
Attention: The path to the old modules is deprecated and will be removed in ENGAGE v7:
import { getCurrentSearchQuery } from '@shopgate/pwa-common/selectors/router';
Parameters
state
(Object) required: The application state.props
(Object) : An object containing props.routeId
(string): Can be passed to select a specific route from the stack.
Returns
(string|null): The search query. If nothing was found, it returns null
.
getCurrentState
Retrieves the state of the current visible route from the store. A route state can be set via the update
helper which is
provided by the useNavigation hook.
Usage
import { getCurrentState } from '@shopgate/engage/core';
Attention: The path to the old modules is deprecated and will be removed in ENGAGE v7:
import { getCurrentState } from '@shopgate/pwa-common/selectors/router';
Parameters
state
(Object) required: The application state.props
(Object) : An object containing props.routeId
(string): Can be passed to select a specific route from the stack.
Returns
(Object|null): The route state. If nothing was found, it returns null
.