@equinor/fusion-framework-module-navigation 7.0.9 → 7.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/esm/version.js +1 -1
  2. package/dist/esm/version.js.map +1 -1
  3. package/dist/tsconfig.tsbuildinfo +1 -1
  4. package/dist/types/version.d.ts +1 -1
  5. package/package.json +10 -7
  6. package/CHANGELOG.md +0 -600
  7. package/src/NavigateEvent.ts +0 -47
  8. package/src/NavigatedEvent.ts +0 -35
  9. package/src/NavigationConfigurator.interface.ts +0 -41
  10. package/src/NavigationConfigurator.ts +0 -226
  11. package/src/NavigationProvider.interface.ts +0 -99
  12. package/src/NavigationProvider.ts +0 -436
  13. package/src/__tests__/BrowserHistory.test.ts +0 -151
  14. package/src/__tests__/HashHistory.test.ts +0 -121
  15. package/src/__tests__/MemoryHistory.test.ts +0 -185
  16. package/src/__tests__/NavigationProvider.test.ts +0 -302
  17. package/src/__tests__/ProxyHistory.test.ts +0 -149
  18. package/src/__tests__/setup.ts +0 -8
  19. package/src/enable-navigation.ts +0 -60
  20. package/src/index.ts +0 -51
  21. package/src/lib/BaseHistory.ts +0 -255
  22. package/src/lib/BrowserHistory.ts +0 -124
  23. package/src/lib/BrowserHistoryHashStack.ts +0 -57
  24. package/src/lib/BrowserHistoryStack.ts +0 -96
  25. package/src/lib/MemoryHistory.ts +0 -76
  26. package/src/lib/MemoryHistoryStack.ts +0 -118
  27. package/src/lib/ProxyHistory.ts +0 -145
  28. package/src/lib/create-history.ts +0 -58
  29. package/src/lib/index.ts +0 -33
  30. package/src/lib/state/actions.ts +0 -108
  31. package/src/lib/state/check-blockers.ts +0 -52
  32. package/src/lib/state/create-flow.ts +0 -36
  33. package/src/lib/state/create-history-reducer.ts +0 -77
  34. package/src/lib/state/create-store.ts +0 -39
  35. package/src/lib/state/flow-creators.ts +0 -7
  36. package/src/lib/state/go.ts +0 -20
  37. package/src/lib/state/history.state.ts +0 -14
  38. package/src/lib/state/index.ts +0 -4
  39. package/src/lib/state/navigate.ts +0 -58
  40. package/src/lib/state/pop.ts +0 -24
  41. package/src/lib/state/validate-current-location.ts +0 -33
  42. package/src/lib/types.ts +0 -190
  43. package/src/lib/utils/encode-trailing-whitespace.ts +0 -18
  44. package/src/lib/utils/has-protocol.ts +0 -21
  45. package/src/lib/utils/index.ts +0 -5
  46. package/src/lib/utils/path-to-string.ts +0 -24
  47. package/src/lib/utils/path-to-url.ts +0 -52
  48. package/src/lib/utils/resolve-browser-location.ts +0 -1
  49. package/src/lib/utils/resolve-hash-location.ts +0 -26
  50. package/src/lib/utils/resolve-path.ts +0 -22
  51. package/src/lib/utils/resolve-window-location.ts +0 -24
  52. package/src/module.ts +0 -80
  53. package/src/version.ts +0 -2
  54. package/tsconfig.json +0 -24
  55. package/vitest.config.ts +0 -14
@@ -1,57 +0,0 @@
1
- import { BrowserHistoryStack } from './BrowserHistoryStack';
2
- import type { Location, To } from './types';
3
- import { resolveHashLocation, resolvePath, pathToString } from './utils';
4
-
5
- /**
6
- * Browser history hash stack implementation using hash-based routing.
7
- *
8
- * Uses URL hash fragment (#) instead of pathname. The hash is not sent to the server,
9
- * allowing routing without server configuration.
10
- *
11
- * @example
12
- * ```ts
13
- * // Regular routing: https://example.com/users
14
- * // Hash routing: https://example.com/#/users
15
- * const stack = new BrowserHistoryHashStack(window);
16
- * ```
17
- */
18
- export class BrowserHistoryHashStack extends BrowserHistoryStack {
19
- /**
20
- * Gets the current location from window.location.hash.
21
- * @returns The current hash-derived navigation location.
22
- */
23
- public get current(): Readonly<Location> {
24
- return resolveHashLocation(this._window);
25
- }
26
-
27
- /**
28
- * Creates a URL object for a given path with hash-based routing.
29
- *
30
- * Uses the current window location as the base and only modifies the hash fragment.
31
- * The path is normalized to ensure it starts with '#' if not already present.
32
- *
33
- * @param to - The target path (string, Path object, or Location object)
34
- * @returns A URL object with the path in the hash fragment
35
- *
36
- * @example
37
- * ```ts
38
- * // If current URL is 'https://example.com/app'
39
- * createURL('/users?id=1')
40
- * // URL { href: 'https://example.com/app#/users?id=1', ... }
41
- *
42
- * createURL({ pathname: '/dashboard', search: '?tab=settings' })
43
- * // URL { href: 'https://example.com/app#/dashboard?tab=settings', ... }
44
- * ```
45
- */
46
- public override createURL(to: To): URL {
47
- const path = resolvePath(to);
48
- const fullPath = pathToString(path);
49
- // Normalize: ensure path starts with '#' for hash routing
50
- const hashPath = fullPath.startsWith('#') ? fullPath : `#${fullPath}`;
51
- // Use current location as base, only modify hash
52
- const url = new URL(this._window.location.href, this.origin);
53
- url.hash = hashPath;
54
-
55
- return url;
56
- }
57
- }
@@ -1,96 +0,0 @@
1
- import { pathToString, resolvePath, resolveWindowLocation } from './utils';
2
- import type { HistoryStack, Location, To } from './types';
3
-
4
- /**
5
- * Browser history stack implementation using the native History API.
6
- *
7
- * Manages navigation state via `pushState` / `replaceState` and stores
8
- * location state in `history.state`. This is the default stack for
9
- * pathname-based (non-hash) routing.
10
- *
11
- * @example
12
- * ```ts
13
- * const stack = new BrowserHistoryStack(window);
14
- * stack.push({ pathname: '/users', search: '', hash: '', key: 'abc', state: null });
15
- * ```
16
- */
17
- export class BrowserHistoryStack implements HistoryStack {
18
- /**
19
- * @param _window - The window object to use for history operations
20
- */
21
- public constructor(protected readonly _window: Window) {}
22
-
23
- /**
24
- * Gets the origin of the history stack.
25
- * @returns The browser origin used as the URL base.
26
- */
27
- public get origin(): string {
28
- return this._window.location.origin;
29
- }
30
-
31
- /**
32
- * Gets the current location.
33
- * @returns The current browser location converted to a navigation location.
34
- */
35
- public get current(): Location {
36
- return resolveWindowLocation(this._window);
37
- }
38
-
39
- /**
40
- * Pushes a new entry onto the history stack.
41
- * @param location - Location to append to browser history.
42
- */
43
- public push(location: Location): void {
44
- this.navigate(location, 'PUSH');
45
- }
46
-
47
- /**
48
- * Replaces the current entry in the history stack.
49
- * @param location - Location to replace in browser history.
50
- */
51
- public replace(location: Location): void {
52
- this.navigate(location, 'REPLACE');
53
- }
54
-
55
- /**
56
- * Navigates to a location with the specified action.
57
- * @param location - Location to navigate to.
58
- * @param action - Native history action to perform.
59
- */
60
- public navigate(location: Location, action: 'PUSH' | 'REPLACE'): void {
61
- const relativePath = this._createRelativePath(location);
62
- const state = { value: location.state, key: location.key };
63
- // Select the native operation matching the requested navigation action.
64
- if (action === 'PUSH') {
65
- this._window.history.pushState(state, '', relativePath);
66
- } else {
67
- this._window.history.replaceState(state, '', relativePath);
68
- }
69
- }
70
-
71
- /**
72
- * Navigates backward or forward in the history stack.
73
- * @param delta - Number of entries to move backward or forward.
74
- */
75
- public go(delta: number): void {
76
- this._window.history.go(delta);
77
- }
78
-
79
- /**
80
- * Creates a URL object for a given path.
81
- * @param to - Target path or partial path object.
82
- * @returns URL resolved against the browser origin.
83
- */
84
- public createURL(to: To): URL {
85
- return new URL(pathToString(resolvePath(to)), this.origin);
86
- }
87
-
88
- /**
89
- * Creates the relative URL path used by native browser history.
90
- * @param to - Target path or partial path object.
91
- * @returns Relative URL path for browser history.
92
- */
93
- protected _createRelativePath(to: To): string {
94
- return pathToString(this.createURL(to));
95
- }
96
- }
@@ -1,76 +0,0 @@
1
- import { type To, type LocationState, type NavigationUpdate, Action } from './types';
2
- import { pathToString, resolvePath } from './utils';
3
- import { MemoryHistoryStack } from './MemoryHistoryStack';
4
- import { BaseHistory } from './BaseHistory';
5
- import { createHistoryReducer, createStore } from './state';
6
-
7
- /**
8
- * Default initial location for memory history.
9
- */
10
- const defaultInitialLocation: NavigationUpdate = {
11
- delta: 0,
12
- action: Action.Pop,
13
- location: {
14
- pathname: '/',
15
- search: '',
16
- hash: '',
17
- key: 'unknown',
18
- state: null,
19
- unstable_mask: undefined,
20
- },
21
- };
22
-
23
- /**
24
- * Options for configuring a MemoryHistory instance.
25
- */
26
- export type MemoryHistoryOptions = {
27
- /** Optional initial location */
28
- initialLocation?: NavigationUpdate;
29
- /** Optional initial history entries */
30
- initialHistory?: NavigationUpdate[];
31
- };
32
-
33
- /**
34
- * Memory history implementation using in-memory storage.
35
- *
36
- * Does not touch browser APIs, making it suitable for:
37
- * - **Testing** — deterministic navigation state without a DOM
38
- * - **SSR** — server-side rendering where `window` is unavailable
39
- * - **Widgets** — embedded apps that must not alter the host page URL
40
- * - **Node.js** — any environment without browser history APIs
41
- */
42
- export class MemoryHistory extends BaseHistory {
43
- /** @param options - Optional initial location and history entries. */
44
- public constructor(options?: MemoryHistoryOptions) {
45
- const { initialLocation, initialHistory } = options ?? {};
46
- const initial = initialLocation ?? defaultInitialLocation;
47
-
48
- // create initial state for memory history
49
- const initialState: LocationState = {
50
- current: initial,
51
- history: initialHistory ?? [initial],
52
- blockers: [],
53
- };
54
-
55
- // create stack for memory history
56
- const stack = new MemoryHistoryStack({ initialLocation: initialState.current.location });
57
-
58
- // initialize state with stack and reducer
59
- const state = createStore(
60
- stack,
61
- createHistoryReducer(() => initialState, { maxHistory: 100 }),
62
- );
63
-
64
- super(state);
65
- }
66
-
67
- /**
68
- * Creates a URL object for a given path using memory:// origin.
69
- * @param to - Target path or partial path object.
70
- * @returns URL resolved against memory://.
71
- */
72
- public createURL(to: To): URL {
73
- const path = pathToString(resolvePath(to));
74
- return new URL(path, 'memory://');
75
- }
76
- }
@@ -1,118 +0,0 @@
1
- import type { HistoryStack, Location, LocationState, To } from './types';
2
- import { pathToString, resolvePath } from './utils';
3
-
4
- /**
5
- * Memory-based history stack implementation.
6
- *
7
- * Stores navigation state in memory instead of using browser APIs.
8
- * Unlike BrowserHistoryStack, push/replace only update the current location
9
- * (history entries are managed by the reducer, not the stack).
10
- */
11
- export class MemoryHistoryStack implements HistoryStack {
12
- #current: Location;
13
-
14
- /**
15
- * Gets the origin of the history stack.
16
- * Always returns 'memory://' for in-memory storage.
17
- * @returns The fixed origin used for in-memory URLs.
18
- */
19
- get origin(): string {
20
- return 'memory://';
21
- }
22
-
23
- /**
24
- * Gets the current location.
25
- * @returns The current in-memory navigation location.
26
- */
27
- get current(): Location {
28
- return this.#current;
29
- }
30
-
31
- /**
32
- * Creates a memory history stack instance.
33
- *
34
- * @param options - Configuration options
35
- * @param options.initialLocation - Optional initial location (defaults to '/')
36
- */
37
- constructor(options?: { initialLocation?: Location }) {
38
- this.#current = options?.initialLocation ?? {
39
- pathname: '/',
40
- search: '',
41
- hash: '',
42
- state: null,
43
- key: '',
44
- unstable_mask: undefined,
45
- };
46
- }
47
-
48
- /**
49
- * Pushes a new entry onto the history stack.
50
- *
51
- * Only updates the current location. History entries are managed by the reducer.
52
- * @param location - Location to make current.
53
- */
54
- push(location: Location): void {
55
- this.#current = location;
56
- }
57
-
58
- /**
59
- * Replaces the current entry in the history stack.
60
- *
61
- * Only updates the current location. History entries are managed by the reducer.
62
- * @param location - Location to make current.
63
- */
64
- replace(location: Location): void {
65
- this.#current = location;
66
- }
67
-
68
- /**
69
- * Navigates backward or forward in the history stack.
70
- *
71
- * Uses the history state to find the target location by index.
72
- * Clamps to valid range (first or last entry if out of bounds).
73
- *
74
- * @param delta - Number of steps to move (negative for back, positive for forward)
75
- * @param state - Current location state with history entries
76
- */
77
- go(delta: number, state: Readonly<LocationState>): void {
78
- const { history, current } = state;
79
- const currentLocation = current.location ?? this.#current;
80
- // Find current location in history by key
81
- // Locate the current entry so relative navigation can preserve stack boundaries.
82
- const currentIndex = history.findIndex((entry) => entry.location.key === currentLocation.key);
83
-
84
- // If current location not found, use last entry
85
- // Fall back to the newest entry when the stack cannot identify the current location.
86
- if (currentIndex === -1) {
87
- // Restore the latest known entry when the history cannot locate the current key.
88
- if (history.length > 0) {
89
- this.#current = history[history.length - 1].location;
90
- }
91
- return;
92
- }
93
-
94
- // Calculate target index and clamp to valid range
95
- const newIndex = currentIndex + delta;
96
- // Clamp the destination to the available history range.
97
- if (newIndex < 0) {
98
- this.#current = state.history[0].location;
99
- // Use the oldest entry when navigation moves beyond the end of the stack.
100
- } else if (newIndex >= state.history.length) {
101
- this.#current = state.history[state.history.length - 1].location;
102
- } else {
103
- this.#current = state.history[newIndex].location;
104
- }
105
- }
106
-
107
- /**
108
- * Creates a URL object for a given path.
109
- *
110
- * All URLs use the 'memory://' origin since this is in-memory storage.
111
- * @param to - Target path or partial path object.
112
- * @returns URL resolved against memory://.
113
- */
114
- createURL(to: To): URL {
115
- const path = resolvePath(to);
116
- return new URL(pathToString(path), this.origin);
117
- }
118
- }
@@ -1,145 +0,0 @@
1
- import { Subscription } from 'rxjs';
2
- import type { Observable } from 'rxjs';
3
-
4
- import type { BaseHistory } from './BaseHistory';
5
- import type {
6
- History,
7
- NavigateOptions,
8
- NavigationBlocker,
9
- NavigationListener,
10
- NavigationUpdate,
11
- Path,
12
- To,
13
- } from './types';
14
- import type { Actions } from './state/actions';
15
-
16
- /**
17
- * A lightweight proxy that delegates every {@link History} operation to an
18
- * underlying target instance.
19
- *
20
- * Use this when you need to pass a conforming `History` object whose backing
21
- * implementation can be swapped or is not yet available at construction time,
22
- * or when you want a thin indirection layer without subclassing
23
- * {@link BaseHistory}.
24
- *
25
- * The proxy does **not** own the underlying history; disposing it only tears
26
- * down subscriptions and blockers registered through the proxy itself.
27
- *
28
- * @example
29
- * ```ts
30
- * const browser = createHistory('browser');
31
- * const proxy = new ProxyHistory(browser);
32
- * proxy.push('/dashboard'); // delegates to browser.push
33
- * ```
34
- */
35
- export class ProxyHistory implements History {
36
- /** The underlying history instance all calls are forwarded to. */
37
- readonly #target: History;
38
-
39
- /** Teardowns owned by this proxy, cleaned up on dispose. */
40
- readonly #teardowns = new Subscription();
41
-
42
- /**
43
- * @param target - The history instance to delegate all operations to
44
- */
45
- constructor(target: History) {
46
- this.#target = target;
47
- }
48
-
49
- /** @inheritdoc */
50
- get state$(): Observable<NavigationUpdate> {
51
- return this.#target.state$;
52
- }
53
-
54
- /** @inheritdoc */
55
- get action$(): Observable<Actions> {
56
- return this.#target.action$;
57
- }
58
-
59
- /** @inheritdoc */
60
- get action(): History['action'] {
61
- return this.#target.action;
62
- }
63
-
64
- /** @inheritdoc */
65
- get location(): History['location'] {
66
- return this.#target.location;
67
- }
68
-
69
- /** @inheritdoc */
70
- createHref(to: To): string {
71
- return this.#target.createHref(to);
72
- }
73
-
74
- /** @inheritdoc */
75
- createURL(to: To): URL {
76
- return this.#target.createURL(to);
77
- }
78
-
79
- /** @inheritdoc */
80
- encodeLocation(to: To): Path {
81
- return this.#target.encodeLocation(to);
82
- }
83
-
84
- /** @inheritdoc */
85
- push(to: To, state?: unknown): void {
86
- this.#target.push(to, state);
87
- }
88
-
89
- /** @inheritdoc */
90
- replace(to: To, state?: unknown): void {
91
- this.#target.replace(to, state);
92
- }
93
-
94
- /** @inheritdoc */
95
- navigate(to: To, options?: NavigateOptions): void {
96
- this.#target.navigate(to, options);
97
- }
98
-
99
- /** @inheritdoc */
100
- go(delta: number): void {
101
- this.#target.go(delta);
102
- }
103
-
104
- /**
105
- * Triggers a POP action on the underlying history to notify framework
106
- * listeners (e.g. React Router) after programmatic navigation.
107
- *
108
- * Delegates to the target's `pop()` when it is a {@link BaseHistory}
109
- * instance; otherwise this is a no-op.
110
- */
111
- pop(): void {
112
- // Only BaseHistory implementations expose pop(); anything else is a no-op.
113
- if ('pop' in this.#target && typeof this.#target.pop === 'function') {
114
- (this.#target as BaseHistory).pop();
115
- }
116
- }
117
-
118
- /** @inheritdoc */
119
- listen(listener: NavigationListener): () => void {
120
- const unlisten = this.#target.listen(listener);
121
- this.#teardowns.add(unlisten);
122
- return () => {
123
- unlisten();
124
- this.#teardowns.remove(unlisten);
125
- };
126
- }
127
-
128
- /** @inheritdoc */
129
- block(blocker: NavigationBlocker): VoidFunction {
130
- const unblock = this.#target.block(blocker);
131
- this.#teardowns.add(unblock);
132
- return () => {
133
- unblock();
134
- this.#teardowns.remove(unblock);
135
- };
136
- }
137
-
138
- /**
139
- * Disposes all listeners and blockers registered through this proxy.
140
- * Does **not** dispose the underlying history.
141
- */
142
- [Symbol.dispose](): void {
143
- this.#teardowns.unsubscribe();
144
- }
145
- }
@@ -1,58 +0,0 @@
1
- import { MemoryHistory, type MemoryHistoryOptions } from './MemoryHistory';
2
- import { BrowserHistory, type BrowserHistoryOptions } from './BrowserHistory';
3
- import { BrowserHistoryStack } from './BrowserHistoryStack';
4
- import { BrowserHistoryHashStack } from './BrowserHistoryHashStack';
5
-
6
- type HistoryCtorMap = {
7
- memory: (options?: MemoryHistoryOptions) => MemoryHistory;
8
- browser: (options?: Omit<BrowserHistoryOptions, 'stack'>) => BrowserHistory;
9
- hash: (options?: Omit<BrowserHistoryOptions, 'stack'>) => BrowserHistory;
10
- };
11
-
12
- /**
13
- * Creates a history instance based on the specified type.
14
- *
15
- * Factory function for creating different history implementations:
16
- * - `'browser'`: Creates a {@link BrowserHistory} using pathname-based routing
17
- * - `'hash'`: Creates a {@link BrowserHistory} using hash-based routing (`#/path`)
18
- * - `'memory'`: Creates a {@link MemoryHistory} for testing, SSR, or widget apps
19
- *
20
- * @param type - The type of history to create (`'browser'`, `'hash'`, or `'memory'`)
21
- * @param args - Optional arguments forwarded to the history constructor
22
- * @returns A {@link History} instance of the requested type
23
- * @throws {Error} If `type` is not one of `'browser'`, `'hash'`, or `'memory'`
24
- *
25
- * @example
26
- * ```ts
27
- * const history = createHistory('browser');
28
- * const hashHistory = createHistory('hash');
29
- * const memoryHistory = createHistory('memory', { initialLocation: { ... } });
30
- * ```
31
- */
32
- export const createHistory = <T extends keyof HistoryCtorMap>(
33
- type: T,
34
- ...args: Parameters<HistoryCtorMap[T]>
35
- ): ReturnType<HistoryCtorMap[T]> => {
36
- // Dispatch to the history implementation matching the requested type.
37
- switch (type) {
38
- case 'memory':
39
- return new MemoryHistory(...(args as [MemoryHistoryOptions])) as ReturnType<
40
- HistoryCtorMap[T]
41
- >;
42
- case 'browser': {
43
- const options = args[0] as Omit<BrowserHistoryOptions, 'stack'>;
44
- return new BrowserHistory({ ...options, stack: BrowserHistoryStack }) as ReturnType<
45
- HistoryCtorMap[T]
46
- >;
47
- }
48
- case 'hash': {
49
- const options = args[0] as Omit<BrowserHistoryOptions, 'stack'>;
50
- return new BrowserHistory({ ...options, stack: BrowserHistoryHashStack }) as ReturnType<
51
- HistoryCtorMap[T]
52
- >;
53
- }
54
- default: {
55
- throw new Error(`Invalid history type: ${type}`);
56
- }
57
- }
58
- };
package/src/lib/index.ts DELETED
@@ -1,33 +0,0 @@
1
- /**
2
- * Internal history implementations, stacks, and types.
3
- *
4
- * @remarks
5
- * This sub-module is re-exported as `@equinor/fusion-framework-module-navigation/lib`
6
- * and provides the low-level building blocks for navigation state management.
7
- *
8
- * @packageDocumentation
9
- */
10
-
11
- // History implementations
12
- export { BaseHistory } from './BaseHistory';
13
- export { BrowserHistory } from './BrowserHistory';
14
- export { MemoryHistory } from './MemoryHistory';
15
- export { ProxyHistory } from './ProxyHistory';
16
-
17
- // History stacks
18
- export { BrowserHistoryStack } from './BrowserHistoryStack';
19
- export { BrowserHistoryHashStack as HashHistoryStack } from './BrowserHistoryHashStack';
20
- export { MemoryHistoryStack } from './MemoryHistoryStack';
21
-
22
- // Types
23
- export type {
24
- Action,
25
- History,
26
- HistoryStack,
27
- Location,
28
- NavigateOptions,
29
- NavigationListener,
30
- NavigationUpdate,
31
- Path,
32
- To,
33
- } from './types';
@@ -1,108 +0,0 @@
1
- import { createAction, createAsyncAction } from '@equinor/fusion-observable/actions';
2
- import type { ActionTypes } from '@equinor/fusion-observable/actions';
3
- import { v7 as generateId } from 'uuid';
4
- import type { To, NavigateOptions, NavigationBlocker, NavigationUpdate } from '../types';
5
-
6
- /**
7
- * Action for navigating to a new location (push or replace).
8
- */
9
- const navigateAction = createAsyncAction(
10
- 'navigation/navigate',
11
- (to: To, options: NavigateOptions) => ({
12
- payload: { to, options },
13
- meta: { key: generateId() },
14
- }),
15
- (update: NavigationUpdate) => ({
16
- payload: { update },
17
- }),
18
- (error: Error) => ({
19
- payload: { error },
20
- }),
21
- );
22
-
23
- const abortNavigateAction = createAction('navigation/navigate::abort', (reason?: string) => ({
24
- payload: { reason },
25
- }));
26
-
27
- /**
28
- * Action for navigating backward or forward in history.
29
- */
30
- const goDeltaAction = createAsyncAction(
31
- 'navigation/go',
32
- (delta: number) => ({
33
- payload: { delta },
34
- }),
35
- (update: NavigationUpdate) => ({
36
- payload: { update },
37
- }),
38
- (error: Error) => ({
39
- payload: { error },
40
- }),
41
- );
42
-
43
- /**
44
- * Action for handling browser back/forward navigation (popstate events).
45
- */
46
- const popStateAction = createAsyncAction(
47
- 'navigation/pop',
48
- (update?: NavigationUpdate) => ({
49
- payload: { update },
50
- }),
51
- (update: NavigationUpdate) => ({
52
- payload: { update },
53
- }),
54
- (error: Error) => ({
55
- payload: { error },
56
- }),
57
- );
58
-
59
- /**
60
- * Action for validating the current location against history state.
61
- */
62
- const validateLocationAction = createAsyncAction(
63
- 'navigation/navigationValidation',
64
- () => ({
65
- payload: {},
66
- }),
67
- (update: NavigationUpdate) => ({
68
- payload: { update },
69
- }),
70
- (error: Error) => ({
71
- payload: { error },
72
- }),
73
- );
74
-
75
- /**
76
- * Action for adding a navigation blocker.
77
- */
78
- const addBlockerAction = createAction('navigation/addBlocker', (blocker: NavigationBlocker) => ({
79
- payload: { blocker },
80
- }));
81
-
82
- /**
83
- * Action for removing a navigation blocker.
84
- */
85
- const removeBlockerAction = createAction(
86
- 'navigation/removeBlocker',
87
- (blocker: NavigationBlocker) => ({
88
- payload: { blocker },
89
- }),
90
- );
91
-
92
- /**
93
- * Navigation actions for history state management.
94
- */
95
- export const actions = {
96
- navigate: navigateAction,
97
- abortNavigate: abortNavigateAction,
98
- go: goDeltaAction,
99
- pop: popStateAction,
100
- validateLocation: validateLocationAction,
101
- addBlocker: addBlockerAction,
102
- removeBlocker: removeBlockerAction,
103
- };
104
-
105
- /**
106
- * Union type of all navigation actions.
107
- */
108
- export type Actions = ActionTypes<typeof actions>;