Skip to content

docs(zh): add file-based routing related configuration documentation#2643

Merged
posva merged 4 commits intovuejs:mainfrom
hooray:main
Mar 5, 2026
Merged

docs(zh): add file-based routing related configuration documentation#2643
posva merged 4 commits intovuejs:mainfrom
hooray:main

Conversation

@hooray
Copy link
Copy Markdown
Contributor

@hooray hooray commented Feb 27, 2026

Summary by CodeRabbit

  • Documentation
    • Added comprehensive Chinese guides for file-based routing: getting started, file conventions, configuration options, extending routes, HMR, and ESLint guidance, with examples and migration notes.
  • Navigation
    • Updated the Chinese site navigation with a new, expanded "基于文件的路由" section linking the new guides for easier discovery.

@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 27, 2026

Deploy Preview for vue-router ready!

Name Link
🔨 Latest commit bf4276b
🔍 Latest deploy log https://app.netlify.com/projects/vue-router/deploys/69a2b7a445c252000880c3e6
😎 Deploy Preview https://deploy-preview-2643--vue-router.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 96 (🟢 up 2 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0bdba30 and bf4276b.

📒 Files selected for processing (3)
  • packages/docs/zh/file-based-routing/file-based-routing.md
  • packages/docs/zh/file-based-routing/hmr.md
  • packages/docs/zh/file-based-routing/index.md
✅ Files skipped from review due to trivial changes (1)
  • packages/docs/zh/file-based-routing/index.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/docs/zh/file-based-routing/file-based-routing.md

📝 Walkthrough

Walkthrough

Adds a new Chinese sidebar section "基于文件的路由" and six new zh documentation pages covering file-based routing usage, file conventions, configuration, route extension, HMR, and ESLint. No code or public API signatures were changed.

Changes

Cohort / File(s) Summary
Navigation Configuration
packages/docs/.vitepress/config/zh.ts
Added a new /zh/ sidebar section "基于文件的路由" with six expanded entries linking to the new docs.
File-Based Routing Docs
packages/docs/zh/file-based-routing/index.md, packages/docs/zh/file-based-routing/file-based-routing.md, packages/docs/zh/file-based-routing/configuration.md, packages/docs/zh/file-based-routing/extending-routes.md, packages/docs/zh/file-based-routing/hmr.md, packages/docs/zh/file-based-routing/eslint.md
Added six Chinese documentation pages: setup and migration across build tools; file naming and routing conventions; configuration options (routesFolder, extensions, filePatterns, exclude, dts, getRouteName, pathParser, extendRoute, beforeWriteFiles, etc.); route extension points (extendRoute, beforeWriteFiles, definePage, <route> blocks); HMR usage patterns (handleHotUpdate); and ESLint guidance for auto-routes/definePage.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Custom Route Resolvers #2415 — Touches the same VitePress Chinese sidebar config (packages/docs/.vitepress/config/zh.ts) and may overlap on sidebar ordering or keys.

Suggested reviewers

  • posva
  • LittleSound

Poem

🐇 翻页轻跃入文档,
文件路由织新桥,
配置、扩展与热替换,
ESLint 同步随行,
兔子一跳庆更新 🎉

🚥 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 The title accurately describes the main change: adding Chinese (zh) documentation for file-based routing configuration, which aligns with all six new documentation files and the sidebar configuration added in this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

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

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.

Copy link
Copy Markdown
Contributor

@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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/docs/zh/file-based-routing/extending-routes.md`:
- Line 57: Update the internal anchor links so they match VitePress's Chinese
auto-generated anchors: replace the link target
"./file-based-routing#routes-folder-structure" with
"./file-based-routing#路由文件夹结构" (referencing the "路由文件夹结构" heading) and replace
the link to "hmr.md#runtime-routes" (or similar English anchor) with
"hmr.md#运行时路由" (referencing the "运行时路由" heading); edit the markdown links in the
extending-routes.md content where those anchors are used so they point to the
exact Chinese heading anchors.

In `@packages/docs/zh/file-based-routing/file-based-routing.md`:
- Line 75: Update the sentence that currently reads "注意文件夹和文件的名称 `users/`
可以是任何有效的命名,如 `my-[id]-param/`。" to improve readability by replacing “有效的命名” with
either “有效命名” or “合法名称” (choose one consistent term), keeping the examples
`users/` and `my-[id]-param/` intact; locate the text containing those examples
to make this small wording change.
- Around line 150-156: 示例对象中用于命名视图的字段写错了:把当前的 "component" 改为
"components"(即在该路由对象里将 `component: { aux: () =>
import('src/pages/index@aux.vue') }` 更正为使用 `components`),以符合 Vue Router
的命名视图用法并避免误导读者;保留内部 `aux` 命名视图函数和 import 路径不变。

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11f8268 and 7c7786b.

📒 Files selected for processing (7)
  • packages/docs/.vitepress/config/zh.ts
  • packages/docs/zh/file-based-routing/configuration.md
  • packages/docs/zh/file-based-routing/eslint.md
  • packages/docs/zh/file-based-routing/extending-routes.md
  • packages/docs/zh/file-based-routing/file-based-routing.md
  • packages/docs/zh/file-based-routing/hmr.md
  • packages/docs/zh/file-based-routing/index.md

Comment thread packages/docs/zh/file-based-routing/extending-routes.md Outdated
Comment thread packages/docs/zh/file-based-routing/file-based-routing.md Outdated
Comment on lines +150 to +156
```js
{
path: '/',
component: {
aux: () => import('src/pages/index@aux.vue')
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Search for Vue Router named views documentation and examples
web_search
Vue Router named views route record components property

Repository: vuejs/router

Length of output: 148


🏁 Script executed:

# Also check if we can find the Vue Router source to verify the API
cd /tmp && git clone --depth 1 https://github.com/vuejs/router.git 2>/dev/null
find /tmp/router -type f -name "*.md" | xargs grep -l "named.*view\|components:" | head -5

Repository: vuejs/router

Length of output: 349


🏁 Script executed:

# Search for examples of named views in Vue Router docs
find /tmp/router -type f -name "*.md" -o -name "*.ts" | xargs grep -A 5 "components\s*:" | head -40

Repository: vuejs/router

Length of output: 38


🏁 Script executed:

# Read the named views documentation
cat /tmp/router/packages/docs/guide/advanced/named-views.md | head -150

Repository: vuejs/router

Length of output: 143


🏁 Script executed:

# Search for route record definitions and examples in source
find /tmp/router/packages/router/src -type f -name "*.ts" | xargs grep -A 5 "components\s*:" | head -80

Repository: vuejs/router

Length of output: 6242


🏁 Script executed:

# Look at the types definition for route records
find /tmp/router/packages/router/src -type f -name "*types*" | head -5
cat /tmp/router/packages/router/src/types/index.ts | grep -A 20 "RouteRecordRaw\|components"

Repository: vuejs/router

Length of output: 5293


命名视图片段字段名写错:应为 components 而不是 component

Line 151-155 当前写法会误导读者,命名视图在 Vue Router 中使用 components

🩹 Proposed fix
 {
   path: '/',
-  component: {
+  components: {
     aux: () => import('src/pages/index@aux.vue')
   }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/docs/zh/file-based-routing/file-based-routing.md` around lines 150 -
156, 示例对象中用于命名视图的字段写错了:把当前的 "component" 改为 "components"(即在该路由对象里将 `component: {
aux: () => import('src/pages/index@aux.vue') }` 更正为使用 `components`),以符合 Vue
Router 的命名视图用法并避免误导读者;保留内部 `aux` 命名视图函数和 import 路径不变。

Copy link
Copy Markdown
Contributor

@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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/docs/zh/file-based-routing/extending-routes.md`:
- Around line 7-22: The example uses __dirname in beforeWriteFiles which is
undefined in ESM; fix by importing fileURLToPath from 'node:url' and defining
__dirname using fileURLToPath(new URL('.', import.meta.url)) before using
path.join in beforeWriteFiles (keep symbols: import of VueRouter, path,
fileURLToPath, const __dirname = fileURLToPath(...), and the
beforeWriteFiles/root.insert call).

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c7786b and c9bcda4.

📒 Files selected for processing (2)
  • packages/docs/zh/file-based-routing/extending-routes.md
  • packages/docs/zh/file-based-routing/file-based-routing.md
✅ Files skipped from review due to trivial changes (1)
  • packages/docs/zh/file-based-routing/file-based-routing.md

Comment on lines +7 to +22
```ts
import VueRouter from 'vue-router/vite'
import path from 'node:path'

VueRouter({
extendRoute(route) {
if (route.name === '/[name]') {
route.addAlias('/hello-vite-:name')
}
},

beforeWriteFiles(root) {
root.insert('/from-root', path.join(__dirname, './src/pages/index.vue'))
},
})
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, check if the documentation file exists and read the relevant lines
fd -t f "extending-routes.md" packages/docs/

Repository: vuejs/router

Length of output: 164


🏁 Script executed:

# Check the router package.json exports to verify if 'vue-router/vite' is a valid export
cat packages/router/package.json | jq '.exports'

Repository: vuejs/router

Length of output: 2120


🏁 Script executed:

# Search for usage patterns of vue-router/vite in the codebase
rg "vue-router/vite" -t ts -t js -t vue

Repository: vuejs/router

Length of output: 83


🏁 Script executed:

# Also check for vite-plugin-pages imports to understand the pattern
rg "vite-plugin-pages|vite-plugin-vue-layouts" -t ts -t js -t md -A 2 -B 2 | head -50

Repository: vuejs/router

Length of output: 2337


🏁 Script executed:

# Read the actual file content at the specified lines
sed -n '1,30p' packages/docs/zh/file-based-routing/extending-routes.md

Repository: vuejs/router

Length of output: 598


🏁 Script executed:

# Check how __dirname is handled in existing Vite plugin examples
rg "__dirname" -t ts -t js packages/ -A 2 -B 2 | head -60

Repository: vuejs/router

Length of output: 2745


🏁 Script executed:

# Look for Vite config examples in the documentation
fd -t f "vite.config" packages/docs/ 
rg "vite.config|vite.config.ts" packages/docs/ -t ts -t md -A 5 | head -40

Repository: vuejs/router

Length of output: 2650


第 19 行的 __dirname 在 ESM 环境中未定义,代码示例需要修复。

导入路径 import VueRouter from 'vue-router/vite' 是有效的。但在 Vite 配置文件的 ESM 上下文中,__dirname 不会自动可用,使用它会导致 ReferenceError

在 ESM 中,需要先定义 __dirname

import { fileURLToPath } from 'node:url'
const __dirname = fileURLToPath(new URL('.', import.meta.url))

修正后的完整示例:

修正的代码示例
import VueRouter from 'vue-router/vite'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

const __dirname = fileURLToPath(new URL('.', import.meta.url))

VueRouter({
  extendRoute(route) {
    if (route.name === '/[name]') {
      route.addAlias('/hello-vite-:name')
    }
  },

  beforeWriteFiles(root) {
    root.insert('/from-root', path.join(__dirname, './src/pages/index.vue'))
  },
})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/docs/zh/file-based-routing/extending-routes.md` around lines 7 - 22,
The example uses __dirname in beforeWriteFiles which is undefined in ESM; fix by
importing fileURLToPath from 'node:url' and defining __dirname using
fileURLToPath(new URL('.', import.meta.url)) before using path.join in
beforeWriteFiles (keep symbols: import of VueRouter, path, fileURLToPath, const
__dirname = fileURLToPath(...), and the beforeWriteFiles/root.insert call).

Comment thread packages/docs/.vitepress/config/zh.ts Outdated
Comment thread packages/docs/zh/file-based-routing/configuration.md Outdated
Comment thread packages/docs/zh/file-based-routing/configuration.md Outdated
Comment thread packages/docs/zh/file-based-routing/configuration.md Outdated
Comment thread packages/docs/zh/file-based-routing/configuration.md Outdated
Co-authored-by: edison <daiwei521@126.com>
Comment thread packages/docs/zh/file-based-routing/file-based-routing.md Outdated
Comment thread packages/docs/zh/file-based-routing/file-based-routing.md Outdated
Comment thread packages/docs/zh/file-based-routing/file-based-routing.md Outdated
Comment thread packages/docs/zh/file-based-routing/file-based-routing.md Outdated
Comment thread packages/docs/zh/file-based-routing/file-based-routing.md Outdated
Comment thread packages/docs/zh/file-based-routing/hmr.md Outdated
Comment thread packages/docs/zh/file-based-routing/hmr.md Outdated
Comment thread packages/docs/zh/file-based-routing/index.md Outdated
Comment thread packages/docs/zh/file-based-routing/index.md Outdated
Comment thread packages/docs/zh/file-based-routing/index.md Outdated
@edison1105
Copy link
Copy Markdown
Member

LGTM.

@posva posva merged commit 7b3dc27 into vuejs:main Mar 5, 2026
6 checks passed
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.

3 participants