reactjs - 如何使用useRoute在app.js中显示当前屏幕名称?
问题描述
我正在尝试在 app.js 中获取当前屏幕名称,我在通知处理程序中使用 useRoute 但未显示。
Notifications.setNotificationHandler({
handleNotification: (n) => {
const { keeperId, type } = n?.request?.content?.data ?? {};
const route = useRoute();
console.log('route name');
console.log(route.name)
const showNotification = keeperId === store.getState().chat.chat.keeperUserId;
return new Promise((resolve) =>
resolve({
shouldShowAlert: showNotification,
shouldPlaySound: false,
shouldSetBadge: false,
}),
);
},
});
解决方案
我解决了这个问题
export const navigationRef = React.createRef();
navigationRef.current.getCurrentRoute().name
推荐阅读
- java - 禁用菜单项?
- c - 解决 C 警告 - 取消引用空指针
- java - 如何解决 SensorEventListener 操作单独线程中出现的 ANR 问题?
- reactjs - 输入值不随嵌套状态更新
- c# - 集成 Microsoft Identity MSAL 后 azurewebsites.net webapp 上出现未经授权的 401 错误。本地主机工作
- reactjs - 如何连接由 webpack 创建的初始 css/js 文件?
- azure-application-insights - Application Insights 如何推断客户端的设备型号?
- sql - 需要从 XML 列获取 XML 数据到其他列
- powershell - 从文件夹复制文件,然后删除一些文件异常
- reactjs - 具有许多菜单项的 Material-UI Select 组件速度很慢 - 替代解决方案