@equinor/fusion-framework-module-navigation

中文文档
8.0.0发布于 2026/11/12ISCTypeScriptES Module近 30 天下载 1.2万

Navigation module for Fusion Framework providing routing and navigation capabilities using React Router 7

原始使用文档
文档目录18 节
  1. Features
  2. Safe operational telemetry
  3. Installation
  4. Usage
  5. Enable the module
  6. Programmatic navigation
  7. Observable navigation state
  8. Create href / URL
  9. Router integration (legacy)
  10. History types
  11. Navigation blocking
  12. API Reference
  13. Functions
  14. Classes
  15. Interfaces & Types
  16. Events
  17. Configuration
  18. See Also

@equinor/fusion-framework-module-navigation

Routing and navigation module for Fusion Framework with observable state management and automatic basename localization.

Features

  • Path localization — consumers work with clean paths (/users) while the history stack receives full paths (/apps/my-app/users).
  • Observable state — navigation state exposed as an RxJS observable (state$) with shareReplay semantics.
  • Multiple history types — browser (pathname), hash (#/path), and memory (no URL changes).
  • Router compatibility — createRouter() creates @remix-run/router instances wired to the framework history.
  • Navigation blocking — intercept navigations with history.block() and optionally retry.
  • Telemetry & events — dispatches NavigateEvent / NavigatedEvent and tracks actions via the telemetry module.

Safe operational telemetry

INavigationProvider extends the shared TelemetryConnectable contract. Navigation retains its existing Navigation::* notifications rather than adopting new operational record names.

After initialization, navigation connects available host telemetry without waiting for it during startup. Explicit setTelemetry(provider) takes precedence; setTelemetry(undefined) disables automatic hookup. Automatic wiring reports Navigation::navigated without per-action debug chatter.

Telemetry no longer includes locations, previous locations, route state, or action payloads. Detailed explicit-provider action events use the static Navigation::action name with the controlled action type only. Update consumers of the old dynamic names or payload fields. Navigation business events and routing behavior are unchanged. See Operational telemetry.

Installation

pnpm add @equinor/fusion-framework-module-navigation

Usage

Enable the module

import { enableNavigation } from '@equinor/fusion-framework-module-navigation';

// Minimal — basename only
enableNavigation(configurator, '/apps/my-app');

// Advanced — full configuration
enableNavigation(configurator, {
  configure: (config) => {
    config.setBasename('/apps/my-app');
    config.setHistory(createHistory('browser'));
  },
});

Programmatic navigation

const navigation = framework.modules.navigation;

navigation.push('/users');             // adds history entry
navigation.replace('/login');          // replaces current entry
navigation.push('/users', { id: 1 }); // with state

console.log(navigation.path.pathname); // '/users' — basename removed

Observable navigation state

import { filter } from 'rxjs';

navigation.state$.subscribe(({ action, location }) => {
  console.log(action, location.pathname); // 'PUSH' '/users'
});

navigation.state$.pipe(
  filter(({ action }) => action === 'POP'),
).subscribe(({ location }) => {
  console.log('Back/forward to', location.pathname);
});

Create href / URL

// basename = '/apps/my-app'
navigation.createHref('/users');
// → '/apps/my-app/users'

navigation.createURL('/users');
// → URL { pathname: '/apps/my-app/users', ... }

Router integration (legacy)

Note: Prefer @equinor/fusion-framework-react-router for new applications.

import type { AgnosticRouteObject } from '@remix-run/router';

const routes: AgnosticRouteObject[] = [
  { path: '/', element: <Home /> },
  { path: '/users/:id', element: <UserDetail /> },
];

const router = navigation.createRouter(routes);

Always use navigation.createRouter() instead of createBrowserRouter() directly—creating a router outside the provider breaks basename handling and state synchronisation.

History types

Factory argumentClassDescription
'browser'BrowserHistoryPathname-based routing via the History API. Default.
'hash'BrowserHistory (hash stack)Hash-fragment routing (#/path). No server config needed.
'memory'MemoryHistoryIn-memory history. Ideal for widgets, tests, and SSR.
import { createHistory } from '@equinor/fusion-framework-module-navigation';

const browserHistory = createHistory('browser');
const hashHistory    = createHistory('hash');
const memoryHistory  = createHistory('memory');

Navigation blocking

const unblock = navigation.history.block((transition) => {
  if (hasUnsavedChanges) {
    showConfirmDialog(() => {
      unblock();          // remove blocker first
      transition.retry(); // then retry navigation
    });
  } else {
    unblock();
    transition.retry();
  }
});

API Reference

Functions

ExportDescription
enableNavigation(configurator, opts?)Registers the navigation module on a configurator.
createHistory(type, ...args)Factory for BrowserHistory, hash-based BrowserHistory, or MemoryHistory.

Classes

ExportDescription
NavigationProviderModule provider — manages state, localization, and lifecycle.
NavigationConfiguratorFluent config builder with Zod validation.
BrowserHistoryHistory backed by browser pushState / replaceState.
MemoryHistoryHistory backed by in-memory storage.

Interfaces & Types

ExportDescription
INavigationProviderPublic contract for the navigation provider.
INavigationConfiguratorConfiguration shape (basename, history, telemetry, eventProvider).
HistoryHistory instance contract (observable state + navigation methods).
Path{ pathname, search, hash }
LocationPath extended with state and key.
Tostring | Partial<Path> — target for navigation operations.
ActionEnum: Pop, Push, Replace.
NavigationUpdate{ delta, action, location } emitted by state$.

Events

EventWhenCancelable
NavigateEvent (onNavigate)Before navigationYes
NavigatedEvent (onNavigated)After navigationNo

Configuration

OptionTypeDefaultDescription
basenamestringundefinedURL path prefix stripped from / prepended to consumer paths.
historyHistoryBrowser history (or memory in Node)History instance created via createHistory().
telemetryITelemetryProviderAuto-resolvedTracks navigation events and errors.
eventProviderIEventModuleProviderAuto-resolvedDispatches onNavigate / onNavigated events.

See Also

版本与发布记录

@equinor/fusion-framework-module-navigation 共发布 103 个版本,首次发布于 2022/11/17;过去 12 个月发布了 24 个版本。

版本发布日期距今
8.0.0latest2026/11/121 天前
8.0.0-next.1next2026/11/112 天前
8.0.0-next.02026/10/2816 天前
7.0.122026/10/1727 天前
7.0.12-trusted-publishing-20261015-9dfe7602cd2a49a8a9df00d62c26e7304a82a85atrusted-publishing-202610152026/10/1629 天前
7.0.112026/10/121 个月前

其他发布通道:navigator → 1.0.7-navigator.0,apploader → 5.0.3-apploader-be21a6b60eb13eee8bf869e75002d8634e9c50a9,cli-search-index → 6.0.1-cli-search-index.0,msal-v5 → 6.0.1-msal-v5.0,trusted-publishing-20261015 → 7.0.12-trusted-publishing-20261015-9dfe7602cd2a49a8a9df00d62c26e7304a82a85a,next → 8.0.0-next.1。

关于 @equinor/fusion-framework-module-navigation 的常见问题

@equinor/fusion-framework-module-navigation 是什么?

Navigation module for Fusion Framework providing routing and navigation capabilities using React Router 7

如何安装 @equinor/fusion-framework-module-navigation?

在项目目录运行 npm install @equinor/fusion-framework-module-navigation,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:rxjs(^7.0.0)、@remix-run/router(^1.0.0)、@equinor/fusion-observable(^9.2.6)、@equinor/fusion-framework-module(^6.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@equinor/fusion-framework-module-navigation 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@equinor/fusion-framework-module-navigation 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@equinor/fusion-framework-module-navigation 可以商用吗?

@equinor/fusion-framework-module-navigation 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@equinor/fusion-framework-module-navigation 的下载量有多少?

根据 npm 官方下载统计,@equinor/fusion-framework-module-navigation 在 2026/10/14 – 2026/11/12 这 30 天内被下载 12,114 次,日均约 404 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@equinor/fusion-framework-module-navigation 还在维护吗?

最新版本 8.0.0 发布于 2026/11/12(1 天前);至今共发布 103 个版本,其中过去 12 个月发布了 24 个;首次发布于 2022/11/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。