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(client): add VPLink #1435

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/guide/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ Take our documentation source files as an example:

```vue
<template>
<RouterLink to="/">Home</RouterLink>
<RouterLink to="/reference/config.html">Config Reference</RouterLink>
<RouterLink to="/guide/getting-started.html">Getting Started</RouterLink>
<RouterLink to="/guide/">Guide</RouterLink>
<RouterLink to="/reference/config.html#links">Config Reference &gt; markdown.links</RouterLink>
<VPLink to="/">Home</VPLink>
<VPLink to="/reference/config.html">Config Reference</VPLink>
<VPLink to="/guide/getting-started.html">Getting Started</VPLink>
<VPLink to="/guide/">Guide</VPLink>
<VPLink to="/reference/config.html#links">Config Reference &gt; markdown.links</VPLink>
<a href="https://github.com" target="_blank" rel="noopener noreferrer">GitHub</a>
</template>
```
Expand All @@ -82,7 +82,7 @@ Take our documentation source files as an example:

**Explanation**

- Internal links will be converted to `<RouterLink>` for SPA navigation.
- Internal links will be converted to `<VPLink>` which is similar to `<RouterLink>` for SPA navigation.
- Internal links to `.md` files will be converted to the [page route path](./page.md#routing), and both absolute path and relative path are supported.
- External links will get `target="_blank" rel="noopener noreferrer"` attrs.

Expand Down
19 changes: 19 additions & 0 deletions docs/reference/client-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ Client API is provided by [@vuepress/client](https://www.npmjs.com/package/@vuep
- Also see:
- [Guide > Assets > Base Helper](../guide/assets.md#base-helper)


## getPagesPath

- Details:

Returns all pages path, replacement of `router.getRoutes()`.

## isPageExist

- Details:

Returns whether the corresponding path has a page.

## resolve

- Details:

Returns the route and related page metadata corresponding to the path, replacement of `router.resolve()`.

## Constants

There are some constants that available in the client side code.
Expand Down
23 changes: 22 additions & 1 deletion docs/reference/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
- Props:
- pageKey
- Type: `string`
- Required: `false`
- Required: No`

- Usage:

Expand All @@ -44,3 +44,24 @@

- Also see:
- [Node API > Page Properties > key](./node-api.md#key)

## VPLink

- Props:
- to
- Type: `string`
- Required: Yes

- Usage:

```md
<VPLink to="/path/to/link" />
```

- Details:

This component will render an `<a>` link that has SPA navigation capabilities, and will trigger `router.push` when clicked.

Its `to` property is the link to navigate to.

This component is mainly used to replace `<RouterLink>`, which has expensive initialization. If you need to place internal links and don't care about its exact rendering href and activate state, you should use it as first choice.
10 changes: 6 additions & 4 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ const defaultOptions = {

Options for VuePress built-in markdown-it links plugin.

It will convert internal links to `<RouterLink>`, and add extra attributes and icon to external links.
It will convert internal links to `<VPLink>` (similar to `<RouterLink>` with SPA navigation support), and add extra attributes and icon to external links.

Set to `false` to disable this plugin.

Expand All @@ -595,15 +595,17 @@ const defaultOptions = {

#### markdown.links.internalTag

- Type: `'a' | 'RouterLink'`
- Type: `'a' | 'RouterLink' | 'VPLink'`

- Default: `'RouterLink'`
- Default: `'VPLink'`

- Details:

Tag for internal links.

By default, this plugin will transform internal links to `<RouterLink>`. You can set this option to `'a'` to disable this feature.
By default, this plugin will transform internal links to `<VPLink>` with SPA navigation support.

You can set this option to `'RouterLink'` for standard router link with exact route resolving and active and exactActive state, or set this option to `'a'` to disable this feature.

#### markdown.links.externalAttrs

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/frontmatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ permalinkPattern: :year/:month/:day/:slug.html
- [Frontmatter > permalink](#permalink)
- [Node API > Page Properties > permalink](./node-api.md#permalink)

## routeMeta
## meta

- Type: `Record<string, unknown>`

Expand All @@ -198,7 +198,7 @@ permalinkPattern: :year/:month/:day/:slug.html
Custom data to be attached to the page route.

- Also see:
- [Node API > Page Properties > routeMeta](./node-api.md#routeMeta)
- [Node API > Page Properties > meta](./node-api.md#meta)

## title

Expand Down
6 changes: 3 additions & 3 deletions docs/reference/node-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ interface MarkdownLink {
- [Frontmatter > permalink](./frontmatter.md#permalink)
- [Frontmatter > permalinkPattern](./frontmatter.md#permalinkpattern)

### routeMeta
### meta

- Type: `Record<string, unknown>`

Expand All @@ -614,11 +614,11 @@ interface MarkdownLink {
Custom data to be attached to the route record of vue-router.

- Also see:
- [Frontmatter > routeMeta](./frontmatter.md#routemeta)
- [Frontmatter > meta](./frontmatter.md#meta)
- [vue-router > API Reference > RouteRecordRaw > meta](https://router.vuejs.org/api/#meta)

::: tip What's the difference between route meta and page data?
Both [route meta](#routemeta) and [page data](#data) is available in client side. However, route meta is attached to the route record, so the route meta of all pages would be loaded at once when users enter your site. In the contrast, page data is saved in separated files, which would be loaded only when users enter the corresponding page.
Both [route meta](#meta) and [page data](#data) is available in client side. However, route meta is attached to the route record, so the route meta of all pages would be loaded at once when users enter your site. In the contrast, page data is saved in separated files, which would be loaded only when users enter the corresponding page.

Therefore, it's not recommended to store large amounts of info into route meta, otherwise the initial loading speed will be affected a lot when your site has a large number of pages.
:::
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/plugin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export default {

This hook can be used for adding extra properties or modifying current properties on `Page` object.

Notice that changes to `page.data` and `page.routeMeta` can be used in client side code.
Notice that changes to `page.data` and `page.meta` can be used in client side code.

- Example:

Expand Down Expand Up @@ -325,7 +325,7 @@ export default {
- Also see:
- [Client API > usePageData](./client-api.md#usepagedata)
- [Node API > Page Properties > data](./node-api.md#data)
- [Node API > Page Properties > routeMeta](./node-api.md#routemeta)
- [Node API > Page Properties > meta](./node-api.md#meta)

## Lifecycle Hooks

Expand Down
10 changes: 5 additions & 5 deletions docs/reference/plugin/toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ interface TocPropsOptions {
containerClass: string
listClass: string
itemClass: string
linkTag: 'a' | 'RouterLink'
linkTag: 'a' | 'RouterLink' | 'VPLink'
linkClass: string
linkActiveClass: string
linkChildrenActiveClass: string
Expand All @@ -122,7 +122,7 @@ const defaultOptions = {
containerClass: 'vuepress-toc',
listClass: 'vuepress-toc-list',
itemClass: 'vuepress-toc-item',
linkTag: 'RouterLink',
linkTag: 'VPLink',
linkClass: 'vuepress-toc-link',
linkActiveClass: 'active',
linkChildrenActiveClass: 'active',
Expand All @@ -148,18 +148,18 @@ const defaultOptions = {
<!-- item -->
<li class="vuepress-toc-item">
<!-- link -->
<RouterLink class="vuepress-toc-link" to="#foo">Foo</RouterLink>
<VPLink class="vuepress-toc-link" to="#foo">Foo</VPLink>
</li>
<!-- item with children -->
<li class="vuepress-toc-item">
<!-- link (children active) -->
<RouterLink class="vuepress-toc-link active" to="#bar">Bar</RouterLink>
<VPLink class="vuepress-toc-link active" to="#bar">Bar</VPLink>
<!-- list (children) -->
<ul class="vuepress-toc-list">
<!-- item -->
<li class="vuepress-toc-item">
<!-- link (active) -->
<RouterLink class="vuepress-toc-link active" to="#bar-child">Bar Child</RouterLink>
<VPLink class="vuepress-toc-link active" to="#bar-child">Bar Child</VPLink>
</li>
</ul>
</li>
Expand Down
12 changes: 6 additions & 6 deletions docs/zh/guide/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ VuePress 会使用 [markdown-it](https://github.com/markdown-it/markdown-it) 来

```vue
<template>
<RouterLink to="/zh/">首页</RouterLink>
<RouterLink to="/zh/reference/config.html">配置参考</RouterLink>
<RouterLink to="/zh/guide/getting-started.html">快速上手</RouterLink>
<RouterLink to="/zh/guide/">指南</RouterLink>
<RouterLink to="/zh/reference/config.html#links">配置参考 &gt; markdown.links</RouterLink>
<VPLink to="/zh/">首页</VPLink>
<VPLink to="/zh/reference/config.html">配置参考</VPLink>
<VPLink to="/zh/guide/getting-started.html">快速上手</VPLink>
<VPLink to="/zh/guide/">指南</VPLink>
<VPLink to="/zh/reference/config.html#links">配置参考 &gt; markdown.links</VPLink>
<a href="https://github.com" target="_blank" rel="noopener noreferrer">GitHub</a>
</template>
```
Expand All @@ -83,7 +83,7 @@ VuePress 会使用 [markdown-it](https://github.com/markdown-it/markdown-it) 来

**解释**

- 内部链接会被转换为 `<RouterLink>` 以便进行 SPA 导航。
- 内部链接会被转换为和 `<RouterLink>` 类似的 `<VPLink>` 以便进行 SPA 导航。
- 指向 `.md` 文件的内部链接会被转换为目标页面的 [路由路径](./page.md#路由),并且支持绝对路径和相对路径。
- 外部链接会被添加 `target="_blank" rel="noopener noreferrer"` 属性。

Expand Down
18 changes: 18 additions & 0 deletions docs/zh/reference/client-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@
- 参考:
- [指南 > 静态资源 > Base Helper](../guide/assets.md#base-helper)

## getPagesPath

- 详情:

返回所有页面路径,替代 `router.getRoutes()`。

## isPageExist

- 详情:

返回对应的路径是否存在相应页面。

## resolve

- 详情:

返回路径对应的最终路径和相关页面的元数据,替代 `router.resolve()`。

## 常量

在客户端代码中有一些常量可以使用。
Expand Down
27 changes: 24 additions & 3 deletions docs/zh/reference/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

如果一个组件在 `setup()` 中直接使用 浏览器 / DOM API ,它会导致构建过程报错,因为这些 API 在 Node.js 的环境中是无法使用的。在这种情况下,你可以选择一种方式:

- 修改这个组件,只在 `onBeforeMount()` 或 `onMounted()` Hook 中使用 浏览器 / DOM API 。
- 修改这个组件,只在 `onBeforeMount()` 或 `onMounted()` Hook 中使用 浏览器 / DOM API 。
- 使用 `<ClientOnly>` 包裹这个组件。

## Content

- Props:
- 属性:
- pageKey
- 类型: `string`
- 是否必须: `false`
- 必要: 否

- 使用:

Expand All @@ -44,3 +44,24 @@

- 参考:
- [Node API > Page 属性 > key](./node-api.md#key)

## VPLink

- 属性:
- to
- 类型: `string`
- 必要: 是

- 使用:

```md
<VPLink to="/path/to/link" />
```

- 详情:

该组件会渲染一个拥有 SPA 导航能力的 `<a>` 链接,点击时会触发 `router.push` 行为。

它的 `to` 属性是需要导航到的链接。

该组件主要用于替代初始化开销过大的 `<RouterLink>` ,如果你需要放置内部链接且不关注准确的解析地址以及激活状态,你应该首选使用它。
10 changes: 6 additions & 4 deletions docs/zh/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ const defaultOptions = {

VuePress 内置的 markdown-it 链接插件的配置项。

它可以把站内链接转换为 `<RouterLink>` ,并且可以在站外链接上添加额外的属性和图标。
它可以把站内链接转换为 `<VPLink>` (类似于 `<RouterLink>`,提供 SPA 导航) ,并且可以在站外链接上添加额外的属性和图标。

设置为 `false` 可以禁用该插件。

Expand All @@ -608,15 +608,17 @@ const defaultOptions = {

#### markdown.links.internalTag

- 类型: `string`
- 类型: `'a' | 'RouterLink' | 'VPLink'`

- 默认值: `'RouterLink'`
- 默认值: `'VPLink'`

- 详情:

内部链接所使用的标签。

默认情况下,该插件会把内部链接转换为 `<RouterLink>` 。你可以把该选项设置为 `'a'` 来禁用这个功能。
默认情况下,该插件会把内部链接转换为 `<VPLink>`,以提供 SPA 导航。

你可以将该选项设置为 `'RouterLink'` 来渲染为带有准确路由解析以及激活和准确激活状态的 `<RouterLink>`。也可以将该选项设置为 `'a'` 来禁用这个功能。

#### markdown.links.externalAttrs

Expand Down
4 changes: 2 additions & 2 deletions docs/zh/reference/frontmatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ permalinkPattern: :year/:month/:day/:slug.html
- [Frontmatter > permalink](#permalink)
- [Node API > Page 属性 > permalink](./node-api.md#permalink)

## routeMeta
## meta

- 类型: `Record<string, unknown>`

Expand All @@ -198,7 +198,7 @@ permalinkPattern: :year/:month/:day/:slug.html
附加到页面路由的自定义数据。

- 参考:
- [Node API > Page 属性 > routeMeta](./node-api.md#routeMeta)
- [Node API > Page 属性 > meta](./node-api.md#meta)

## title

Expand Down
6 changes: 3 additions & 3 deletions docs/zh/reference/node-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ interface MarkdownLink {
- [Frontmatter > permalinkPattern](./frontmatter.md#permalinkpattern)


### routeMeta
### meta

- 类型: `Record<string, unknown>`

Expand All @@ -609,11 +609,11 @@ interface MarkdownLink {
附加到 vue-router 路由记录上的额外数据。

- 参考:
- [Frontmatter > routeMeta](./frontmatter.md#routemeta)
- [Frontmatter > meta](./frontmatter.md#meta)
- [vue-router > API 参考 > RouteRecordRaw > meta](https://router.vuejs.org/zh/api/#meta)

::: tip Route Meta 和 Page Data 的区别是什么?
[Route Meta](#routemeta) 和 [Page Data](#data) 都可以在客户端代码中使用。然而, Route Meta 是附加在路由记录上的,因此当用户进入你的站点时,所有页面的 Route Meta 都会立即被加载。相比之下, Page Data 是存储在单独的文件中的,只有在用户进入对应页面时才会被加载。
[Route Meta](#meta) 和 [Page Data](#data) 都可以在客户端代码中使用。然而, Route Meta 是附加在路由记录上的,因此当用户进入你的站点时,所有页面的 Route Meta 都会立即被加载。相比之下, Page Data 是存储在单独的文件中的,只有在用户进入对应页面时才会被加载。

因此,不建议在 Route Meta 中存储大量的信息,否则在站点有很多页面时,将会影响站点的初始加载速度。
:::
Expand Down
4 changes: 2 additions & 2 deletions docs/zh/reference/plugin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export default {

该 Hook 可以用来在 Page 对象上添加额外的属性,或修改现有的属性等。

值得一提的是,针对 `page.data` 和 `page.routeMeta` 的改动可以在客户端代码中使用。
值得一提的是,针对 `page.data` 和 `page.meta` 的改动可以在客户端代码中使用。

- 示例:

Expand Down Expand Up @@ -325,7 +325,7 @@ export default {
- 参考:
- [客户端 API > usePageData](./client-api.md#usepagedata)
- [Node API > Page 属性 > data](./node-api.md#data)
- [Node API > Page 属性 > routeMeta](./node-api.md#routemeta)
- [Node API > Page 属性 > meta](./node-api.md#meta)

## 生命周期 Hooks

Expand Down
Loading