From: Lee <55973914+PeterAlfredLee@users.noreply.github.com> Date: Thu, 6 May 2021 12:42:04 +0000 (+0800) Subject: docs: add a note for use functional component (#922) X-Git-Tag: v4.0.7~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=722ee9d4c5f0380f9ae2b3f9a2e715f764b2b55e;p=thirdparty%2Fvuejs%2Frouter.git docs: add a note for use functional component (#922) --- diff --git a/docs/api/index.md b/docs/api/index.md index 99a6bedd..3ac5747e 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -857,6 +857,18 @@ Route record that can be provided by the user when adding routes via the [`route - **See Also**: [Meta fields](../guide/advanced/meta.md) +:::tip +If you want to use a functional component, make sure to add a `displayName` to it. + +For example: +```js +const HomeView = () => h('div', 'HomePage') +// in TypeScript, you will need to use the FunctionalComponent type +HomeView.displayName = 'HomeView' +const routes = [{ path: '/', component: HomeView }] +``` +::: + ## RouteRecordNormalized Normalized version of a [Route Record](#routerecordraw) diff --git a/docs/zh/api/index.md b/docs/zh/api/index.md index 47b3eb33..91b33084 100644 --- a/docs/zh/api/index.md +++ b/docs/zh/api/index.md @@ -851,6 +851,18 @@ stringifyQuery?: ( - **更多的内容请看**:[Meta 字段](../guide/advanced/meta.md) +:::tip 注意 +如果你想使用函数式组件, 请确保在组件上添加一个 `displayName`。 + +例如: +```js +const HomeView = () => h('div', 'HomePage') +// 使用TypeScript时, 组件需要为 FunctionalComponent 类型 +HomeView.displayName = 'HomeView' +const routes = [{ path: '/', component: HomeView }] +``` +::: + ## RouteRecordNormalized [路由记录](#routerecordraw)的标准化版本