Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: intro routes prop config keepQuery #12228

Merged
merged 2 commits into from
Apr 11, 2024

Conversation

fz6m
Copy link
Member

@fz6m fz6m commented Mar 25, 2024

close #10606

从去年开始反馈较多希望增加的功能:路由表配置 redirect 跳转时,希望能携带参数,故新增一个 keepQuery 选项用来在跳转时保持原 url 参数。

欢迎提出更好的命名意见。

命名的想法:keepQuery / withQuery / keepURLQuery

Summary by CodeRabbit

  • New Features
    • Introduced handling of query parameters in navigation and the ability for custom redirect components.
  • Documentation
    • Updated guides for route management, including handling of query parameters and redirections.

Copy link

vercel bot commented Mar 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
umi ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 25, 2024 0:06am

Copy link

coderabbitai bot commented Mar 25, 2024

Walkthrough

The recent updates focus on enhancing the routing behavior, specifically addressing the issue of query parameters being lost during redirection. The changes include improved handling of query parameters in routes.tsx through new context hooks and a NavigateWithParams component, alongside documentation updates in routes.md to guide users on preserving query parameters during redirects and implementing custom redirection logic.

Changes

File(s) Change Summary
.../src/routes.tsx Refactored imports; added useAppData and useRouteProps; introduced NavigateWithParams for query parameters.
docs/docs/docs/guides/routes.md Updated guide on redirecting without losing query parameters; added info on custom redirect components.

Assessment against linked issues

Objective Addressed Explanation
Preserve query parameters during redirection (#10606)

Poem

In the warren, under moon's bright gaze,
A code rabbit hopped through the maze.
"No query lost," it whispered with glee,
As it tweaked the routes for all to see.
🌟 Through redirects, no data shall part,
With every hop, a clever art.
In code's vast garden, it danced with delight,
A digital rabbit, basking in moonlight. 🐇✨

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2c43662 and 106f534.
Files selected for processing (2)
  • docs/docs/docs/guides/routes.md (1 hunks)
  • packages/renderer-react/src/routes.tsx (2 hunks)
Additional comments: 2
packages/renderer-react/src/routes.tsx (1)
  • 57-66: The implementation of NavigateWithParams correctly appends query parameters to the destination URL when keepQuery is set to true. This aligns with the PR's objective to preserve URL parameters during redirects. However, consider handling edge cases where the original URL might already contain query parameters that conflict with the ones being preserved.

Ensure that potential conflicts between existing and preserved query parameters are handled gracefully, possibly by merging them or giving precedence to one set over the other.

docs/docs/docs/guides/routes.md (1)
  • 124-134: The documentation effectively explains the default behavior of redirects and how to use the keepQuery option to retain original query parameters. This addition will be valuable for developers looking to maintain query parameters across redirects.

docs/docs/docs/guides/routes.md Show resolved Hide resolved
Copy link

codecov bot commented Mar 25, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 28.40%. Comparing base (2c43662) to head (106f534).

Files Patch % Lines
packages/renderer-react/src/routes.tsx 33.33% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12228      +/-   ##
==========================================
- Coverage   28.41%   28.40%   -0.02%     
==========================================
  Files         492      492              
  Lines       15166    15172       +6     
  Branches     3626     3627       +1     
==========================================
  Hits         4310     4310              
- Misses      10084    10089       +5     
- Partials      772      773       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cdx111
Copy link

cdx111 commented Apr 1, 2024

keepSearch

@cdx111
Copy link

cdx111 commented Apr 1, 2024

keepURLSearchParams

@stormslowly stormslowly merged commit b9463e1 into umijs:master Apr 11, 2024
25 checks passed
@Mustang-Galaxy
Copy link

看起来更新到最新版本,问题还是有啊

@fz6m
Copy link
Member Author

fz6m commented Apr 18, 2024

如有问题,需要给一个最小复现。

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.

路由redirect 时,查询参数被删除
4 participants