Skip to content

fix(utils): 🐛 修复 getCurrentPath 在页面为空时可能报错的问题#58

Open
ideal-5 wants to merge 1 commit into
wot-ui:mainfrom
ideal-5:fix/current-path
Open

fix(utils): 🐛 修复 getCurrentPath 在页面为空时可能报错的问题#58
ideal-5 wants to merge 1 commit into
wot-ui:mainfrom
ideal-5:fix/current-path

Conversation

@ideal-5

@ideal-5 ideal-5 commented Feb 9, 2026

Copy link
Copy Markdown

🤔 这个 PR 的性质是?(至少选择一个)

  • 日常 bug 修复
  • 新特性提交
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • CI/CD 改进
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 代码重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

在部分生命周期较早的场景下,
getCurrentPages() 可能返回空数组,
此时 getCurrentPath 中访问 currentPage.route 会导致报错。

本次修改仅增加安全判断(可选链),
避免在页面为空时访问 undefined 属性。

☑️ 请求合并前的自查清单

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充

Summary by CodeRabbit

Bug Fixes

  • 修复了特定条件下可能出现的运行时错误,提升应用稳定性

@netlify

netlify Bot commented Feb 9, 2026

Copy link
Copy Markdown

Deploy Preview for wot-starter ready!

Name Link
🔨 Latest commit 7ac7e56
🔍 Latest deploy log https://app.netlify.com/projects/wot-starter/deploys/69894955928e5f0008d95fc1
😎 Deploy Preview https://deploy-preview-58--wot-starter.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Feb 9, 2026

Copy link
Copy Markdown

Walkthrough

src/utils/index.ts 中使用可选链操作符(optional chaining)替换了直接属性访问,将 currentPage.route 改为 currentPage?.route,防止在 currentPage 未定义时发生运行时错误。

Changes

Cohort / File(s) Summary
防御性编程修复
src/utils/index.ts
添加可选链操作符以安全地访问 route 属性,避免当 currentPageundefined 时的潜在运行时错误。

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 一只兔子轻声道,
可选链来护航,
currentPage 若未现,
代码安全不崩溃,
小小修复大作用!✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地描述了主要变更:修复 getCurrentPath 在页面为空时的错误,与代码变更内容完全一致。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant