Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

react-modal-navigation

Latest version: v1.3.1

Overview

Last scanned
30 Nov 2026
Published
30 Nov 2026
npm package Publisher: fanya0725
18 Versions
1.6K Downloads

Scan summary

react-modal-navigation was last scanned on 30 Nov 2026 at version 1.3.1. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 18 versions; the latest 5 were published within 6 days (25–30 Nov 2026).
  • Findings: No rules fired in version 1.3.1.
  • Downloads: 1,642 downloads.

Versions

18 versions published
Versions and the rules that fired in each
VersionPublishedStatus
1.3.1 LATEST 30 Nov 2026 No rules fired
1.3.0 26 Nov 2026 No rules fired
1.2.1 26 Nov 2026 No rules fired
1.2.0 26 Nov 2026 Not shown
1.1.11 25 Nov 2026 Not shown

No rules fired in 1.3.1

Findings

Findings for v1.3.1. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 1.3.1; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

react-modal-navigation

React 19 多页面弹窗导航组件库。支持 Modal / Drawer / Sheet、页面堆栈、KeepAlive、Promise 返回结果、异步关闭守卫、Footer、Loading、暗黑主题与自动注入样式。

默认自动注入样式,无需手动导入 CSS 文件。

嵌套路由

支持嵌套路由、相对路径、共享父级参数、持久化 Layout 和组级守卫。详见 嵌套路由指南。共享 Layout 仍随实际缓存页面挂载,不提供独立挂载保证。

目录

  1. 安装和快速开始
  2. 对象形式打开弹窗
  3. 弹窗位置与尺寸
  4. 配置优先级与响应式
  5. 页面导航与传参
  6. Promise 结果与关闭守卫
  7. 异步提交与 Loading
  8. 主题与样式覆盖
  9. 事件、可访问性和注意事项
  10. TypeScript

安装和快速开始

npm install react-modal-navigation
import { ModalProvider, useModal } from 'react-modal-navigation';

function Home() {
  const { modal } = useModal();
  return <>
    <button onClick={() => modal.open('editUser')}>居中编辑</button>
    <button onClick={() => modal.open('deviceDrawer')}>右侧设备抽屉</button>
  </>;
}

function UserForm() {
  const { navigation } = useModal();
  return <button onClick={() => navigation.close({ id: 1, name: 'Ada' })}>完成</button>;
}

function DeviceHome() {
  const { navigation } = useModal();
  return <button onClick={() => navigation.navigate('DeviceDetail', { id: 123 })}>查看详情</button>;
}

function DeviceDetail() {
  const { navigation } = useModal();
  return <button onClick={() => navigation.goBack()}>返回</button>;
}

const registry = {
  editUser: {
    initialRoute: 'UserForm',
    modalOptions: { placement: 'center', width: 600, maxHeight: '85dvh' },
    screens: { UserForm: { title: '编辑用户', component: UserForm } },
  },
  deviceDrawer: {
    initialRoute: 'DeviceHome',
    modalOptions: { placement: 'right', width: 520 },
    screens: {
      DeviceHome: { title: '设备', component: DeviceHome },
      DeviceDetail: { title: '设备详情', component: DeviceDetail },
    },
  },
};

export default function App() {
  return <ModalProvider registry={registry}><Home /></ModalProvider>;
}

不需要 import 'react-modal-navigation/style.css',Provider 会自动注入组件样式;业务页面可以使用任意 CSS 方案。

推荐:对象形式打开弹窗

modal.open() 和 modal.openAsync() 现在都支持字符串位置参数及对象参数两种写法,原有代码不需要修改。推荐新项目采用对象形式,避免为了设置位置而传入无意义的 {}。

const { modal } = useModal();

// 推荐:只有名称和布局配置,不需要空的 params
await modal.open({
  name: 'editUser',
  options: { placement: 'bottom', width: '100%', height: '55dvh' },
});

// 带页面参数
await modal.open({
  name: 'editUser',
  params: { userId: 1001 },
  options: { placement: 'center', width: 640 },
});

// Promise 弹窗也支持同样的对象形式
const result = await modal.openAsync({
  name: 'editUser',
  params: { userId: 1001 },
  options: { placement: 'right', width: 520 },
});

// 旧 API 保持兼容
await modal.open('editUser');
await modal.open('editUser', { userId: 1001 });
await modal.open('editUser', {}, { placement: 'bottom', height: '55dvh' });

对象字段说明:

字段 类型 必填 说明
name string 是 registry 中注册的弹窗名称
params unknown 否 传给初始 Screen 的页面参数,默认 {}
options ModalOptions 否 当前弹窗覆盖的布局、尺寸、主题和事件配置

兼容规则: 第一个参数是字符串时继续使用 open(name, params?, overrides?);第一个参数是对象时使用 open({ name, params?, options? })。对象形式不需要再传第二、第三个参数。配置优先级仍为 defaultOptions → modalOptions → options。openAsync 的结果结构不变。

弹窗位置与尺寸

placement 可选值
placement 说明 默认高度 推荐场景
center 居中弹窗 内容高度,受 maxHeight 限制 表单、确认框、详情
left 左侧抽屉 视口高度减去上下缝隙 导航、筛选
right 右侧抽屉(默认) 视口高度减去上下缝隙 设备设置、编辑页
top 顶部弹出层 内容高度 顶部操作面板
bottom 底部弹出层 内容高度 移动端操作、筛选
右侧抽屉:上下左右与视口保持 5px
modal.open('deviceDrawer', { deviceId: 123 }, {
  placement: 'right',
  width: 520,
  viewportGap: 5,
});

左右抽屉的高度固定为 calc(100dvh - 10px)(viewportGap: 5 时),即距视口顶部、底部各 5px;同时距左右视口边缘至少 5px。无需传 height: '100dvh',即使传入 height,左右抽屉仍遵循视口高度规则。

// 左侧抽屉
modal.open('deviceDrawer', {}, { placement: 'left', width: '35vw' });

// 居中弹窗
modal.open('editUser', {}, {
  placement: 'center', width: 680, height: '70dvh', maxHeight: '85dvh',
});

// 底部 Sheet
modal.open('editUser', {}, {
  placement: 'bottom', width: '100%', height: '55dvh',
});

// 顶部 Sheet
modal.open('editUser', {}, {
  placement: 'top', width: 800, height: 320,
});
尺寸预设

size 仅控制宽度,可选 sm(400px)、md(560px)、lg(720px)、xl(960px)、full(100%)。显式 width 优先于 size。不传时默认宽度 460px。

modal.open('editUser', {}, { placement: 'center', size: 'lg' });
modal.open('editUser', {}, { placement: 'center', size: 'lg', width: 640 }); // width 优先
属性 类型 默认 作用
placement center \| left \| right \| top \| bottom right 弹窗位置
size sm \| md \| lg \| xl \| full 未设置 预设宽度
width number \| string 460 弹窗宽度,数字单位 px
height number \| string 自动 居中/顶部/底部高度;左右抽屉强制视口高度
maxWidth number \| string 同 width 最大宽度
maxHeight number \| string 视口减去缝隙 最大高度;左右抽屉强制视口高度
viewportGap number 5 视口四周留白,单位 px
borderRadius number \| string 12 圆角
mobileFullscreen boolean false 宽度 ≤640px 时铺满屏幕,覆盖缝隙规则

视口边界使用 100dvh(动态视口高度),适应移动端浏览器地址栏;内容区域单独滚动,Header / Footer 不跟随内容滚动。viewportGap 应使用有限的非负数字。

配置优先级与响应式

从低到高:ModalProvider.defaultOptions → registry[name].modalOptions → modal.open(name, params, overrides)。

<ModalProvider registry={registry} defaultOptions={{ placement: 'center', size: 'md', viewportGap: 5 }}>
  <App />
</ModalProvider>
const registry = {
  users: {
    initialRoute: 'List',
    modalOptions: { placement: 'right', width: 520 },
    screens: { List: { title: '用户列表', component: UserList } },
  },
};

modal.open('users'); // 默认右侧 520px
modal.open('users', {}, { placement: 'center', width: 700 }); // 本次临时居中
modal.open('users', {}, { mobileFullscreen: true }); // 手机端全屏

注意:mobileFullscreen: true 在宽度 ≤640px 时会覆盖 placement 与 viewportGap,故不再保留 5px 缝隙;需要缝隙时不要启用此项。

页面导航与传参

function UserList() {
  const { navigation } = useModal();
  return <button onClick={() => navigation.navigate('UserDetail', { id: 8 })}>详情</button>;
}

function UserDetail() {
  const { navigation } = useModal();
  const id = navigation.currentRoute?.params?.id;
  return <>
    <p>用户 ID:{id}</p>
    <button onClick={() => navigation.setParams({ tab: 'settings' })}>切换标签</button>
    <button onClick={() => navigation.goBack({ updated: true })}>返回</button>
  </>;
}

navigate 进入路由,goBack(result?) 返回上一页,replace 替换当前页,reset 重置栈,setParams 合并当前页参数。隐藏页面 KeepAlive 保留状态;建议用 useFocusEffect 管理轮询和订阅。

页面跳转方法速查
方法 使用示例 行为
navigate navigation.navigate('UserDetail', { userId: 1 }) 跳转;已有同名页面则复用并截断后续页面
goBack navigation.goBack({ saved: true }) 返回上一页并传回结果;根页面返回 false
replace navigation.replace('Success', { id: 1 }) 替换当前页面
reset navigation.reset('UserList') 重置为新的根页面
setParams navigation.setParams({ tab: 'info' }) 浅合并当前页面参数
close await navigation.close({ id: 1 }) 关闭整个弹窗,不是返回上一页

navigation.canGoBack 判断能否返回;navigation.currentRoute 获取当前页面 { key, name, params };navigation.stack 获取完整导航栈。上一页使用 useNavigationResult(callback) 接收 goBack(result) 的结果,KeepAlive 页面使用 useIsFocused() / useFocusEffect() 管理焦点副作用。

完整的逐项说明、栈变化示例、返回值和注意事项请阅读 API 参考手册 · 第 5 章:页面导航。

Promise 结果与关闭守卫

const { modal } = useModal();
const result = await modal.openAsync('editUser');
if (result.status === 'confirmed') console.log(result.value);
else console.log(result.status, result.reason);

弹窗内部:await navigation.close({ id: 1 }) 返回确认结果。modal.open() 返回 Promise<number | null>(弹窗实例 ID 或阻止打开时 null),不是 openAsync 的业务结果。

modalOptions: {
  onBeforeClose: async ({ reason }) => {
    if (hasUnsavedChanges()) return window.confirm('未保存,确定关闭吗?');
    return true;
  },
  onOpen: ctx => console.log('opened', ctx),
  onClose: ctx => console.log('closed', ctx.reason),
  onNavigate: ctx => console.log('navigated', ctx),
  onFocus: ctx => console.log('focused', ctx),
  onBlur: ctx => console.log('blurred', ctx),
}

关闭被拒绝时弹窗继续存在。替换、取消和 Provider 卸载等情况,openAsync() 返回不同状态与 reason。不要将 onClose 当作弹窗仍处于活动状态的回调。

异步提交与 Loading

import { useModal, useModalTask, useModalLoading } from 'react-modal-navigation';

function SaveScreen() {
  const { navigation } = useModal();
  const { run, pending, error } = useModalTask();
  const save = async () => {
    const result = await run(() => Promise.resolve({ id: 10 }), { loadingText: '保存中...' });
    if (result.status === 'success') await navigation.close(result.value);
  };
  return <>
    {error && <p role="alert">保存失败,请重试</p>}
    <button disabled={pending} onClick={save}>保存</button>
  </>;
}

useModalLoading().showLoading() 返回任务 token,使用 hideLoading(token) 结束对应任务;多个任务并发不会相互误关。useModalTask 阻止同一 Hook 的重复提交,但不会自动取消网络请求。

主题与样式覆盖

<ModalProvider registry={registry} theme="auto"
  backgroundColor={{ light: '#fff', dark: '#334155' }}>
  <App />
</ModalProvider>

不需要导入库的 CSS。已有 className、bodyClassName、headerClassName、footerClassName 可供业务样式覆盖;也可在业务项目中覆盖 --pmn-surface、--pmn-text、--pmn-border 等 CSS 变量。自动注入 CSS 时请注意 CSS 优先级。若站点 CSP 禁止内联样式,可改用 react-modal-navigation/style.css 静态导入,并按需配置 CSP。

事件可访问性和注意事项

  • closeOnOverlay 默认 false;closeOnEsc 默认 true。
  • 对话框有 role="dialog"、aria-modal、Tab 焦点约束、关闭后焦点恢复。
  • 背景滚动被锁定,并补偿滚动条宽度。
  • KeepAlive 页面隐藏时保持组件挂载,轮询/订阅请自行按焦点停止。
  • 若多次调用 open() 或存在异步关闭守卫,建议 await 以避免竞态。
  • 样式注入依赖浏览器 DOM;SSR 时不会直接访问 document。严格 CSP 环境可能需要改为静态 CSS。

TypeScript

公开类型位于 types/index.d.ts,包括 ModalOptions、ModalRegistry、ModalNavigation、ModalResult 等。

import type { ModalRegistry } from 'react-modal-navigation';
const registry: ModalRegistry = {
  demo: { initialRoute: 'Main', modalOptions: { placement: 'right', size: 'lg' }, screens: { Main: { component: Main } } },
};

支持 modal.open({ name, params, options }) 和 modal.openAsync({ name, params, options }),字符串形式继续兼容。

简洁的对象调用

对象调用现在还支持将布局配置直接放在顶层,options 不再是必需的:

const { modal } = useModal();

modal.open({ name: 'editUser', placement: 'bottom', width: '100%', height: '55dvh' });
modal.open({ name: 'editUser', params: { userId: 1001 }, placement: 'right', width: 520 });

// 原有嵌套 options 形式仍然可用
modal.open({ name: 'editUser', options: { placement: 'center', width: 640 } });

两种对象写法都适用于 modal.openAsync()。若同时提供顶层布局参数和 options,options 中的同名配置优先。字符串形式 modal.open('editUser', params, options) 保持兼容。

明确区分确认和取消

新增 modal.confirm(value) 和 modal.dismiss(reason),使 Promise 结果语义更加清晰,尤其是确认时没有返回值的场景。

function EditUser() {
  const { modal } = useModal();
  return <>
    <button onClick={() => modal.confirm({ saved: true })}>保存并关闭</button>
    <button onClick={() => modal.confirm()}>仅确认,不返回数据</button>
    <button onClick={() => modal.dismiss('cancel')}>取消</button>
  </>;
}

const result = await modal.openAsync({ name: 'editUser', placement: 'right', width: 520 });
if (result.status === 'confirmed') {
  // result.value 允许为 undefined,仍属于 confirmed
} else if (result.status === 'dismissed') {
  // result.reason 可能是 cancel、api、escape 等
}

confirm 和 dismiss 均遵守 onBeforeClose 异步关闭守卫;返回 Promise<boolean>,表示是否实际关闭。原有 modal.close(result) 保持不变:传入值视为确认,不传值视为取消。

建议的业务实践

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • npm react-modal-navigation

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Cry2Wolf: How to Tell a Real Bug from a Nothingburger
AI & VibeSec

Cry2Wolf: Not Every Branded Bug Deserves a Fire Drill

The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Vulnerability Insights

The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?

Microsoft's Official agent framework Hijacked
AI & VibeSec

BREAKING: Hijacked Releases of Microsoft’s Official agent-framework Steals Azure and CI Credentials

Frame 2085668439 (1)
Group 1261154229