Skip to content

feat(extendRoutes): allow relative path overrides #519

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

Merged
merged 23 commits into from
Apr 23, 2025

Conversation

robertmoura
Copy link
Contributor

@robertmoura robertmoura commented Oct 4, 2024

BREAKING CHANGE: allow relative path overrides

Closes #341

  • Support relative paths for EditableTreeNode
  • Require absolute paths at the base of the tree and the root's children
  • Support relative paths in definePage and <route> block

Includes changes from #431

Description

Relative paths in definePage and route block

Relative paths are converted to absolute paths. Here is an example:

src/pages/
├─ custom-root.vue
├─ layout.vue
└─ layout/
	└─ folder-without-layout/
		└─ custom-child.vue

custom-root.vue

// Absolute path is '/i-am-custom'
definePage({
    path: 'i-am-custom',
});

custom-child.vue

// Absolute path is '/layout/i-am-custom'
definePage({
    path: 'i-am-custom',
});

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of relative and absolute custom route paths, ensuring that manual path overrides are resolved correctly in nested routes.
    • Adjusted warnings so that only root-level routes require absolute paths, reducing unnecessary alerts for non-root nodes.
    • Enhanced path normalization to automatically prefix root paths with a slash when missing.
    • Fixed path joining utility to always return a valid root path when input is empty or contains only slashes.
  • Tests
    • Added new test cases to verify correct propagation and computation of overridden paths for both relative and absolute values in nested routes.
    • Expanded tests for path joining utility to cover edge cases and ensure consistent path formatting.
    • Updated existing tests to validate use of full path properties instead of partial path segments.

Copy link

codecov bot commented Oct 5, 2024

Codecov Report

Attention: Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.

Project coverage is 62.35%. Comparing base (a0b6c27) to head (8ef4d18).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/core/customBlock.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #519      +/-   ##
==========================================
+ Coverage   61.68%   62.35%   +0.67%     
==========================================
  Files          32       32              
  Lines        3145     3140       -5     
  Branches      580      586       +6     
==========================================
+ Hits         1940     1958      +18     
+ Misses       1199     1176      -23     
  Partials        6        6              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@posva posva moved this from 🆕 New to 🏗 In progress in unplugin-vue-router Apr 22, 2025
Copy link

coderabbitai bot commented Apr 22, 2025

Walkthrough

The changes revise how route path overrides are handled in the routing core. The logic for setting and validating custom route paths is updated to allow non-absolute (relative) paths for non-root nodes, and to propagate relative path overrides correctly through the route tree. The warning for non-absolute paths is now limited to root nodes only. Test coverage is added to verify correct path resolution for both relative and absolute overrides in nested routes. Some validation and warning logic is removed or relocated, and internal getters are updated to reflect the new path resolution behavior.

Changes

Files/Areas Changed Change Summary
src/core/context.ts Added blank line before setting custom route block; no logic changes.
src/core/customBlock.ts Simplified getRouteBlock by removing path validation and warnings for non-absolute paths.
src/core/extendRoutes.ts Modified EditableTreeNode path setter to prefix root node paths with slash if missing; removed warning for non-root.
src/core/treeNodeValue.ts Added fullPath getter; changed path getter to return only overridden or own segment without joining parent.
src/core/tree.ts Updated TreeNode getter fullPath to use value's fullPath; changed isRoot to check fullPath.
src/core/extendRoutes.spec.ts Added tests for manual path overrides, relative/absolute path handling, and path normalization in route nodes.
src/core/tree.spec.ts Updated test assertions to expect fullPath instead of path in route node properties.
src/core/utils.ts Modified joinPath to return '/' if the joined path is empty or falsy.
src/core/utils.spec.ts Added tests for joinPath covering path joining, leading slash, empty segments, and trailing slash preservation.

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Allow non-absolute (relative) paths in EditableTreeNode (#341)
Restrict warnings about non-absolute paths to root nodes only (#341)
Ensure correct path resolution and propagation for relative overrides (#341)
Remove or relocate unnecessary validation/warnings for non-root nodes (#341)

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee95ab5 and 8ef4d18.

📒 Files selected for processing (1)
  • src/core/context.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/core/context.ts

🪧 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>, please review it.
    • Generate unit testing code 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

posva added 2 commits April 23, 2025 10:24
BREAKING CHANGE: If you were relying on EditableTreeNode's `path`
returning a _full path_, you will now need to read `fullPath` instead.
Otherwise, this change should be more intuitive as it allows setting a
relative path.
Copy link
Owner

@posva posva left a comment

Choose a reason for hiding this comment

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

Thanks a lot! I did some refactor to simplify things and ended up aligning the path + fullPath usage. I think it makes more sense this way even though it's a breaking change.

@github-project-automation github-project-automation bot moved this from 🏗 In progress to 👀 In review in unplugin-vue-router Apr 23, 2025
Copy link

pkg-pr-new bot commented Apr 23, 2025

Open in StackBlitz

npm i https://pkg.pr.new/unplugin-vue-router@519

commit: 8ef4d18

@posva posva merged commit 93a977a into posva:main Apr 23, 2025
14 checks passed
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in unplugin-vue-router Apr 23, 2025
@jods4
Copy link
Contributor

jods4 commented Apr 23, 2025

Nice, thanks! 🎉

@robertmoura
Copy link
Contributor Author

Thanks @posva 🎉 Those refactors look great 😊

@robertmoura robertmoura deleted the feat/relative-route-block-paths branch May 6, 2025 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Support non absolute paths in EditableTreeNode
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy