Skip to content

fix: update ja docs #3214

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 20 commits into from
Jun 7, 2020
55 changes: 45 additions & 10 deletions docs/ja/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,49 @@ sidebar: auto

- HTML5 history モードで `base` オプションを使っている時に、 `to` プロパティの URL にそれを含める必要がありません。

### 外側の要素へのアクティブクラスの適用
### `v-slot` API (3.1.0 以降)

アクティブクラスを `<a>` タグ自身よりも、外側の要素に対して適用したいことがあるでしょう。その場合、 `<router-link>` を使って外側の要素を描画して、その内側に生の `<a>` タグをラップすることができます
`router-link` は[スコープ付きスロット](https://jp.vuejs.org/v2/guide/components-slots.html#%E3%82%B9%E3%82%B3%E3%83%BC%E3%83%97%E4%BB%98%E3%81%8D%E3%82%B9%E3%83%AD%E3%83%83%E3%83%88)を通して低レベルなカスタマイズを提供しています。これは、主にライブラリ作者をターゲットにした高度な API ですが、ほとんどの場合 _NavLink_ などのようなカスタムコンポーネントでも同様に開発者にとっても大変便利です

``` html
<router-link tag="li" to="/foo">
<a>/foo</a>
**`v-slot` API を使うとき、それは単一の子を `router-link` に通す必要がります。**そうしない場合は、 `router-linke` は `span` 要素で子をラップします。

```html
<router-link
to="/about"
v-slot="{ href, route, navigate, isActive, isExactActive }"
>
<NavLink :active="isActive" :href="href" @click="navigate"
>{{ route.fullPath }}</NavLink
>
</router-link>
```

- `href`: 解決された url。これは、`a` 要素の `href` 属性になります
- `route`: 解決された正規化済みロケーション
- `navigate`: ナビゲーションをトリガーするための関数。`router-link` と同じように、**必要なときに自動的にイベントが起こらないようにします。**
- `isActive`: [アクティブクラス (active class)](#active-class) が適用されるとき、`true` になります。任意のクラスを適用できます。
- `isExactActive`: `true` if the [正確なアクティブクラス (exact active class)](#exact-active-class) が適用されるとき、`true` になります。 任意のクラスを適用できます。

#### 例: アクティブクラスを外部要素への適用

アクティブクラスを `<a>` タグ自身よりも、外側の要素に対して適用したいことがあるでしょう。その場合、`<router-link>` 内の要素を `v-slot` を使ってリンクを作成することでラップできます。

```html
<router-link
to="/foo"
v-slot="{ href, route, navigate, isActive, isExactActive }"
>
<li
:class="[isActive && 'router-link-active', isExactActive && 'router-link-exact-active']"
>
<a :href="href" @click="navigate">{{ route.fullPath }}</a>
</li>
</router-link>
```

この時、 `<a>` は実際のリンクになります (そして正しい `href` が得られます)。しかし、アクティブクラスは外側の `<li>` に適用されます。
:::tip
`target="_blank"` を `a` 要素に追加する場合、`@click="navigate"` ハンドラを省略しなければなりません。
:::

## `<router-link>` Props

Expand Down Expand Up @@ -112,7 +144,7 @@ sidebar: auto

``` html
<!-- このリンクは `/` だけにアクティブになります -->
<router-link to="/" exact>
<router-link to="/" exact></router-link>
```

アクティブリンククラスをより説明している例としてこちらの [動作](https://jsfiddle.net/8xrk1n9f/) を確認してください。
Expand Down Expand Up @@ -164,8 +196,8 @@ name ではないプロパティも描画されるコンポーネントに渡さ

`RouteConfig` の型宣言:

``` js
declare type RouteConfig = {
``` ts
interface RouteConfig = {
path: string;
component?: Component;
name?: string; // 名前付きルート用
Expand Down Expand Up @@ -313,7 +345,9 @@ router.afterEach((to, from) => {})

``` js
router.push(location, onComplete?, onAbort?)
router.push(location).then(onComplete).catch(onAbort)
router.replace(location, onComplete?, onAbort?)
router.replace(location).then(onComplete).catch(onAbort)
router.go(n)
router.back()
router.forward()
Expand Down Expand Up @@ -462,7 +496,8 @@ router.onError(callback)
const router = new VueRouter({
routes: [
// 以下のオブジェクトがルートレコード
{ path: '/foo', component: Foo,
{ path: '/foo',
component: Foo,
children: [
// こちらもルートレコード
{ path: 'bar', component: Bar }
Expand Down
2 changes: 1 addition & 1 deletion docs/ja/guide/advanced/data-fetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
``` html
<template>
<div class="post">
<div class="loading" v-if="loading">
<div v-if="loading" class="loading">
Loading...
</div>

Expand Down
2 changes: 1 addition & 1 deletion docs/ja/guide/advanced/navigation-guards.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ beforeRouteLeave (to, from, next) {

## 完全なナビゲーション解決フロー
1. ナビゲーションがトリガされる
2. 非アクティブ化されたコンポーネントで leave ガードを呼ぶ
2. 非アクティブ化されたコンポーネントで `beforeRouteLeave` ガードを呼ぶ
3. グローバル `beforeEach` ガードを呼ぶ
4. 再利用されるコンポーネントで `beforeRouteUpdate` ガードを呼ぶ (2.2 以降)
5. ルート設定内の `beforeEnter` を呼ぶ
Expand Down