Skip to content

Commit bd5cbd2

Browse files
ChangJoo Park(λ°•μ°½μ£Ό)yyx990803
authored andcommitted
Translate vue-router in Korean. (#1004)
1 parent 85f20b5 commit bd5cbd2

24 files changed

+1362
-0
lines changed

β€Ždocs/LANGS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
* [2.0 - δΈ­ζ–‡](zh-cn/)
44
* [2.0 - German](de/)
55
* [2.0 - Русский](ru/)
6+
* [2.0 - ν•œκ΅­μ–΄(Korean)](ko/)
67
* [0.7 Docs](old/)

β€Ždocs/ko/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% include "./SUMMARY.md" %}

β€Ždocs/ko/SUMMARY.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# vue-router 2
2+
<!--email_off-->
3+
> μ°Έκ³  : [email protected]λŠ” Vue 2.xμ—μ„œλ§Œ μž‘λ™ν•©λ‹ˆλ‹€. 0.7.x용 λ¬Έμ„œλŠ” [이 κ³³](https://github.com/vuejs/vue-router/tree/1.0/docs/en)μž…λ‹ˆλ‹€.
4+
<!--/email_off-->
5+
**[릴리즈 λ…ΈνŠΈ](https://github.com/vuejs/vue-router/releases)**
6+
7+
- [μ„€μΉ˜](installation.md)
8+
- ν•„μˆ˜ 사항
9+
- [μ‹œμž‘ν•˜κΈ°](essentials/getting-started.md)
10+
- [동적 라우트 λ§€μΉ­](essentials/dynamic-matching.md)
11+
- [μ€‘μ²©λœ 라우트](essentials/nested-routes.md)
12+
- [ν”„λ‘œκ·Έλž˜λ° 방식 λ„€λΉ„κ²Œμ΄μ…˜](essentials/navigation.md)
13+
- [이름을 κ°€μ§„ 라우트](essentials/named-routes.md)
14+
- [이름을 κ°€μ§„ λ·°](essentials/named-views.md)
15+
- [λ¦¬λ‹€μ΄λ ‰νŠΈμ™€ 별칭](essentials/redirect-and-alias.md)
16+
- [HTML5 History λͺ¨λ“œ](essentials/history-mode.md)
17+
- κ³ κΈ‰
18+
- [λ„€λΉ„κ²Œμ΄μ…˜ κ°€λ“œ](advanced/navigation-guards.md)
19+
- [라우트 메타 ν•„λ“œ](advanced/meta.md)
20+
- [μ „ν™˜](advanced/transitions.md)
21+
- [데이터 κ°€μ Έμ˜€κΈ°](advanced/data-fetching.md)
22+
- [슀크둀 λ™μž‘](advanced/scroll-behavior.md)
23+
- [μ§€μ—°λœ λ‘œλ”©](advanced/lazy-loading.md)
24+
- API 레퍼런슀
25+
- [router-link](api/router-link.md)
26+
- [router-view](api/router-view.md)
27+
- [λΌμš°ν„° 객체](api/route-object.md)
28+
- [λΌμš°ν„° μƒμ„±μž μ˜΅μ…˜](api/options.md)
29+
- [λΌμš°ν„° μΈμŠ€ν„΄μŠ€](api/router-instance.md)
30+
- [μ»΄ν¬λ„ŒνŠΈ μ£Όμž…](api/component-injections.md)

β€Ždocs/ko/advanced/data-fetching.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# 데이터 κ°€μ Έμ˜€κΈ°
2+
3+
λ•Œλ‘œλŠ” κ²½λ‘œκ°€ ν™œμ„±ν™”λ  λ•Œ μ„œλ²„μ—μ„œ 데이터λ₯Ό 가져와야 ν•©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, μ‚¬μš©μž ν”„λ‘œνŒŒμΌμ„ λ Œλ”λ§ν•˜κΈ° 전에 μ„œλ²„μ—μ„œ μ‚¬μš©μžμ˜ 데이터λ₯Ό 가져와야 ν•©λ‹ˆλ‹€. μš°λ¦¬λŠ” 두 κ°€μ§€ λ°©λ²•μœΌλ‘œ 이것을 μ‚¬μš© ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
4+
5+
- **탐색 ν›„ κ°€μ Έ 였기**: λ¨Όμ € 탐색을 μˆ˜ν–‰ν•˜κ³  λ“€μ–΄μ˜€λŠ” μ»΄ν¬λ„ŒνŠΈμ˜ 라이프 사이클 ν›…μ—μ„œ 데이터λ₯Ό κ°€μ Έμ˜΅λ‹ˆλ‹€. 데이터λ₯Ό κ°€μ Έ μ˜€λŠ” λ™μ•ˆ λ‘œλ“œ μƒνƒœλ₯Ό ν‘œμ‹œν•©λ‹ˆλ‹€.
6+
7+
- **νƒμƒ‰ν•˜κΈ° 전에 κ°€μ Έ 였기**: 라우트 μž…λ ₯ λ°©μ–΄ λ„€λΉ„κ²Œμ΄μ…˜μœΌλ‘œ λ“€μ–΄κ°€κΈ° 전에 데이터λ₯Ό κ°€μ Έ 였고 데이터λ₯Ό κ°€μ Έμ˜¨ 후에 탐색을 μˆ˜ν–‰ν•©λ‹ˆλ‹€.
8+
9+
μ—„λ°€νžˆ λ§ν•˜λ©΄ 두 κ°€μ§€ λͺ¨λ‘ μœ νš¨ν•œ μ„ νƒμž…λ‹ˆλ‹€. ꢁ극적인 λͺ©ν‘œλŠ” μ‚¬μš©μž κ²½ν—˜μ— 달렀 μžˆμŠ΅λ‹ˆλ‹€.
10+
11+
## 탐색 ν›„ κ°€μ Έ 였기
12+
13+
이 방법을 μ‚¬μš©ν•˜λ©΄ λ“€μ–΄μ˜€λŠ” μ»΄ν¬λ„ŒνŠΈλ₯Ό μ¦‰μ‹œ νƒμƒ‰ν•˜κ³  λ Œλ”λ§ν•˜λ©° μ»΄ν¬λ„ŒνŠΈμ˜ `created` ν›…μ—μ„œ 데이터λ₯Ό κ°€μ Έμ˜΅λ‹ˆλ‹€. λ„€νŠΈμ›Œν¬λ₯Ό 톡해 데이터λ₯Ό κ°€μ Έ μ˜€λŠ” λ™μ•ˆ λ‘œλ“œ μƒνƒœλ₯Ό ν‘œμ‹œ ν•  수 μžˆλŠ” 기회λ₯Ό μ œκ³΅ν•˜λ©° 각 λ·° λ§ˆλ‹€ λ‘œλ“œλ₯Ό λ‹€λ₯΄κ²Œ 처리 ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.
14+
15+
`$route.params.id`λ₯Ό 기반으둜 ν•œ κ²Œμ‹œλ¬Όμ˜ 데이터λ₯Ό κ°€μ Έμ™€μ•Όν•˜λŠ” `Post` μ»΄ν¬λ„ŒνŠΈκ°€ μžˆλ‹€κ³  κ°€μ • ν•΄ λ΄…μ‹œλ‹€ :
16+
17+
``` html
18+
<template>
19+
<div class="post">
20+
<div class="loading" v-if="loading">
21+
Loading...
22+
</div>
23+
24+
<div v-if="error" class="error">
25+
{{ error }}
26+
</div>
27+
28+
<div v-if="post" class="content">
29+
<h2>{{ post.title }}</h2>
30+
<p>{{ post.body }}</p>
31+
</div>
32+
</div>
33+
</template>
34+
```
35+
36+
``` js
37+
export default {
38+
data () {
39+
return {
40+
loading: false,
41+
post: null,
42+
error: null
43+
}
44+
},
45+
created () {
46+
// λ·°κ°€ μƒμ„±λ˜κ³  데이터가 이미 κ°μ‹œ 되고 μžˆμ„ λ•Œ 데이터λ₯Ό κ°€μ Έμ˜¨λ‹€.
47+
this.fetchData()
48+
},
49+
watch: {
50+
// λΌμš°νŠΈκ°€ λ³€κ²½λ˜λ©΄ λ©”μ†Œλ“œλ₯Ό λ‹€μ‹œ ν˜ΈμΆœλ©λ‹ˆλ‹€.
51+
'$route': 'fetchData'
52+
},
53+
methods: {
54+
fetchData () {
55+
this.error = this.post = null
56+
this.loading = true
57+
// getPostλ₯Ό 데이터 κ°€μ Έ 였기 μœ„ν•œ μœ ν‹Έλ¦¬ν‹°/API 래퍼둜 λ³€κ²½ν•©λ‹ˆλ‹€.
58+
getPost(this.$route.params.id, (err, post) => {
59+
this.loading = false
60+
if (err) {
61+
this.error = err.toString()
62+
} else {
63+
this.post = post
64+
}
65+
})
66+
}
67+
}
68+
}
69+
```
70+
71+
## νƒμƒ‰ν•˜κΈ° 전에 κ°€μ Έ 였기
72+
73+
이 μ ‘κ·Ό 방식을 μ‚¬μš©ν•˜λ©΄ μ‹€μ œλ‘œ μƒˆ 경둜둜 μ΄λ™ν•˜κΈ° 전에 데이터λ₯Ό κ°€μ Έμ˜΅λ‹ˆλ‹€.
74+
λ“€μ–΄μ˜€λŠ” μ»΄ν¬λ„ŒνŠΈμ—μ„œ `beforeRouteEnter` κ°€λ“œμ—μ„œ 데이터λ₯Ό κ°€μ Έμ˜¬ 수 있으며 νŽ˜μΉ˜κ°€ μ™„λ£Œλ˜λ©΄ `next`만 호좜 ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
75+
76+
77+
``` js
78+
export default {
79+
data () {
80+
return {
81+
post: null,
82+
error: null
83+
}
84+
},
85+
beforeRouteEnter (to, from, next) {
86+
getPost(to.params.id, (err, post) => {
87+
if (err) {
88+
// 일뢀 μ „μ—­ 였λ₯˜ λ©”μ‹œμ§€ ν‘œμ‹œ
89+
next(false)
90+
} else {
91+
next(vm => {
92+
vm.post = post
93+
})
94+
}
95+
})
96+
},
97+
// κ²½λ‘œκ°€ λ³€κ²½λ˜κ³  이 μ»΄ν¬λ„ŒνŠΈκ°€ 이미 λ Œλ”λ§λœ 경우 λ‘œμ§μ€ μ•½κ°„ λ‹¬λΌμ§‘λ‹ˆλ‹€.
98+
watch: {
99+
$route () {
100+
this.post = null
101+
getPost(this.$route.params.id, (err, post) => {
102+
if (err) {
103+
this.error = err.toString()
104+
} else {
105+
this.post = post
106+
}
107+
})
108+
}
109+
}
110+
}
111+
```
112+
113+
μˆ˜μ‹  뷰에 λŒ€ν•΄ λ¦¬μ†ŒμŠ€λ₯Ό κ°€μ Έ μ˜€λŠ” λ™μ•ˆ μ‚¬μš©μžλŠ” ν˜„μž¬ λ·°λ₯Ό μœ μ§€ν•©λ‹ˆλ‹€. λ”°λΌμ„œ 데이터λ₯Ό κ°€μ Έ μ˜€λŠ” λ™μ•ˆ μ§„ν–‰λ₯  ν‘œμ‹œ μ€„μ΄λ‚˜ μΌμ’…μ˜ ν‘œμ‹œκΈ°λ₯Ό ν‘œμ‹œν•˜λŠ” 것을 μΆ”μ²œν•©λ‹ˆλ‹€. 데이터 κ°€μ Έ μ˜€κΈ°κ°€ μ‹€νŒ¨ν•˜λ©΄ μΌμ’…μ˜ μ „μ—­ κ²½κ³  λ©”μ‹œμ§€λ₯Ό ν‘œμ‹œν•΄μ•Όν•©λ‹ˆλ‹€.

β€Ždocs/ko/advanced/lazy-loading.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# μ§€μ—°λœ λ‘œλ”©
2+
3+
λ²ˆλ“€λŸ¬λ₯Ό μ΄μš©ν•˜μ—¬ 앱을 μ œμž‘ν•  λ•Œ JavaScript λ²ˆλ“€μ΄ μƒλ‹Ήνžˆ 컀져 νŽ˜μ΄μ§€λ‘œλ“œ μ‹œκ°„μ— 영ν–₯을 쀄 수 μžˆμŠ΅λ‹ˆλ‹€. 각 라우트의 μ»΄ν¬λ„ŒνŠΈλ₯Ό λ³„λ„μ˜ λ‹¨μœ„λ‘œ λΆ„ν• ν•˜κ³  경둜λ₯Ό λ°©λ¬Έν•  λ•Œ λ‘œλ“œν•˜λŠ” 것이 효율적일 κ²ƒμž…λ‹ˆλ‹€.
4+
5+
Vue의 [비동기 ꡬ성 μš”μ†Œ κΈ°λŠ₯](http://vuejs.org/guide/components.html#Async-Components)κ³Ό Webpack의 [μ½”λ“œ λΆ„ν•  κΈ°λŠ₯](https://webpack.github.io/docs/code-splitting)을 κ²°ν•©ν•©λ‹ˆλ‹€. 라우트 μ»΄ν¬λ„ŒνŠΈλ₯Ό μ‰½κ²Œ 뢈러올 수 μžˆμŠ΅λ‹ˆλ‹€.
6+
7+
라우트 μ»΄ν¬λ„ŒνŠΈλ₯Ό 비동기 μ»΄ν¬λ„ŒνŠΈλ‘œ μ •μ˜ν•˜λ©΄λ©λ‹ˆλ‹€.
8+
9+
``` js
10+
const Foo = resolve => {
11+
// require.ensureλŠ” Webpack의 μ½”λ“œ 뢄할에 λŒ€ν•œ 특수 κ΅¬λ¬Έμž…λ‹ˆλ‹€.
12+
require.ensure(['./Foo.vue'], () => {
13+
resolve(require('./Foo.vue'))
14+
})
15+
}
16+
```
17+
18+
AMD μŠ€νƒ€μΌ μš”κ΅¬ 사항을 μ‚¬μš©ν•˜λŠ” λ˜λ‹€λ₯Έ μ½”λ“œ λΆ„ν•  ꡬ문도 μžˆμœΌλ―€λ‘œ λ‹€μŒκ³Ό 같이 λ‹¨μˆœν™” ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
19+
20+
``` js
21+
const Foo = resolve => require(['./Foo.vue'], resolve)
22+
```
23+
24+
경둜 μ„€μ •μ—μ„œ 아무것도 λ°”κΏ€ ν•„μš”κ°€ μ—†μŠ΅λ‹ˆλ‹€. 보톡 `Foo`만 μ‚¬μš©ν•˜μ‹­μ‹œμ˜€.
25+
26+
``` js
27+
const router = new VueRouter({
28+
routes: [
29+
{ path: '/foo', component: Foo }
30+
]
31+
})
32+
```
33+
34+
### 같은 묢음둜 μ»΄ν¬λ„ŒνŠΈ κ·Έλ£Ήν™”ν•˜κΈ°
35+
36+
λ•Œλ‘œλŠ” λ™μΌν•œ 라우트 μ•„λž˜μ— μ€‘μ²©λœ λͺ¨λ“  μ»΄ν¬λ„ŒνŠΈλ₯Ό λ™μΌν•œ 비동기 묢음으둜 κ·Έλ£Ήν™” ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 이λ₯Ό μœ„ν•΄ μš°λ¦¬λŠ” μ„Έ 번째 μ „λ‹¬μΈμžλ‘œ `require.ensure`에 묢음 이름을 μ œκ³΅ν•˜μ—¬ [이름을 κ°€μ§„ 묢음](https://webpack.github.io/docs/code-splitting.html#named-chunks)을 μ‚¬μš©ν•΄μ•Όν•©λ‹ˆλ‹€.
37+
38+
``` js
39+
const Foo = r => require.ensure([], () => r(require('./Foo.vue')), 'group-foo')
40+
const Bar = r => require.ensure([], () => r(require('./Bar.vue')), 'group-foo')
41+
const Baz = r => require.ensure([], () => r(require('./Baz.vue')), 'group-foo')
42+
```
43+
44+
Webpack은 λ™μΌν•œ 묢음 이름을 κ°€μ§„ 비동기 λͺ¨λ“ˆμ„ 같은 비동기 묢음으둜 κ·Έλ£Ήν™”ν•©λ‹ˆλ‹€. 이것은 λ˜ν•œ`require.ensure`에 λŒ€ν•œ 쒅속성을 더 이상 λͺ…μ‹œ 적으둜 λ‚˜μ—΄ ν•  ν•„μš”κ°€ μ—†μŒμ„ μ˜λ―Έν•©λ‹ˆλ‹€(λ”°λΌμ„œ 빈 배열을 μ „λ‹¬ν•©λ‹ˆλ‹€).

β€Ždocs/ko/advanced/meta.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# 라우트 메타 ν•„λ“œ
2+
3+
라우트λ₯Ό μ •μ˜ ν•  λ•Œ `meta` ν•„λ“œλ₯Ό ν¬ν•¨μ‹œν‚¬ 수 μžˆμŠ΅λ‹ˆλ‹€.
4+
5+
``` js
6+
const router = new VueRouter({
7+
routes: [
8+
{
9+
path: '/foo',
10+
component: Foo,
11+
children: [
12+
{
13+
path: 'bar',
14+
component: Bar,
15+
// 메타 ν•„λ“œ
16+
meta: { requiresAuth: true }
17+
}
18+
]
19+
}
20+
]
21+
})
22+
```
23+
24+
그렇닀면이 `메타`ν•„λ“œμ— μ–΄λ–»κ²Œ μ ‘κ·Όν•©λ‹ˆκΉŒ?
25+
26+
첫째,`routes` μ„€μ •μ˜ 각 라우트 객체λ₯Ό **라우트 λ ˆμ½”λ“œ** λΌκ³ ν•©λ‹ˆλ‹€. 라우트 λ ˆμ½”λ“œλŠ” 쀑첩 될 수 μžˆμŠ΅λ‹ˆλ‹€. λ”°λΌμ„œ λΌμš°νŠΈκ°€ μΌμΉ˜ν•˜λ©΄ λ‘˜ μ΄μƒμ˜ 라우트 λ ˆμ½”λ“œμ™€ 잠재적으둜 일치 ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
27+
28+
예λ₯Ό λ“€μ–΄, μœ„μ˜ 라우트 κ΅¬μ„±μ—μ„œ URL `/foo/bar`λŠ” μƒμœ„ 라우트 λ ˆμ½”λ“œμ™€ ν•˜μœ„ 라우트 λ ˆμ½”λ“œ λͺ¨λ‘μ™€ μΌμΉ˜ν•©λ‹ˆλ‹€.
29+
30+
λΌμš°νŠΈμ™€ μΌμΉ˜ν•˜λŠ” λͺ¨λ“  라우트 λ ˆμ½”λ“œλŠ” `$route` 객체(그리고 λ„€λΉ„κ²Œμ΄μ…˜ κ°€λ“œμ˜ 라우트 객체)에 `$route.matched` λ°°μ—΄λ‘œ λ…ΈμΆœλ©λ‹ˆλ‹€. κ·ΈλŸ¬λ―€λ‘œ μš°λ¦¬λŠ” `$route.matched`λ₯Ό λ°˜λ³΅ν•˜μ—¬ 라우트 λ ˆμ½”λ“œμ˜ 메타 ν•„λ“œλ₯Ό 검사 ν•  ν•„μš”κ°€ μžˆμŠ΅λ‹ˆλ‹€.
31+
32+
예제 μ‚¬μš© μ‚¬λ‘€λŠ” κΈ€λ‘œλ²Œ λ„€λΉ„κ²Œμ΄μ…˜ κ°€λ“œμ—μ„œ 메타 ν•„λ“œλ₯Ό ν™•μΈν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€.
33+
34+
``` js
35+
router.beforeEach((to, from, next) => {
36+
if (to.matched.some(record => record.meta.requiresAuth)) {
37+
// 이 λΌμš°νŠΈλŠ” 인증이 ν•„μš”ν•˜λ©° 둜그인 ν•œ 경우 ν™•μΈν•˜μ‹­μ‹œμ˜€.
38+
// κ·Έλ ‡μ§€ μ•Šμ€ 경우 둜그인 νŽ˜μ΄μ§€λ‘œ λ¦¬λ””λ ‰μ…˜ν•˜μ‹­μ‹œμ˜€.
39+
if (!auth.loggedIn()) {
40+
next({
41+
path: '/login',
42+
query: { redirect: to.fullPath }
43+
})
44+
} else {
45+
next()
46+
}
47+
} else {
48+
next() // λ°˜λ“œμ‹œ next()λ₯Ό ν˜ΈμΆœν•˜μ‹­μ‹œμ˜€!
49+
}
50+
})
51+
```
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# λ„€λΉ„κ²Œμ΄μ…˜ κ°€λ“œ
2+
3+
μ΄λ¦„μ—μ„œ μ•Œ 수 μžˆλ“―μ΄ `vue-router`κ°€ μ œκ³΅ν•˜λŠ” λ„€λΉ„κ²Œμ΄μ…˜ κ°€λ“œλŠ” 주둜 λ¦¬λ””λ ‰μ…˜ν•˜κ±°λ‚˜ μ·¨μ†Œν•˜μ—¬ λ„€λΉ„κ²Œμ΄μ…˜μ„ λ³΄ν˜Έν•˜λŠ” 데 μ‚¬μš©λ©λ‹ˆλ‹€. 라우트 탐색 ν”„λ‘œμ„ΈμŠ€μ— μ—°κ²°ν•˜λŠ” λ°©λ²•μ—λŠ” μ „μ—­, λΌμš°νŠΈλ³„ λ˜λŠ” μ»΄ν¬λ„ŒνŠΈκ°€ μžˆμŠ΅λ‹ˆλ‹€.
4+
5+
### μ „μ—­ κ°€λ“œ
6+
7+
`router.beforeEach`λ₯Ό μ‚¬μš©ν•˜μ—¬ 보호 이전에 μ „μ—­ 등둝을 ν•  수 μžˆμŠ΅λ‹ˆλ‹€ :
8+
9+
``` js
10+
const router = new VueRouter({ ... })
11+
12+
router.beforeEach((to, from, next) => {
13+
// ...
14+
})
15+
```
16+
17+
λ„€λΉ„κ²Œμ΄μ…˜μ΄ 트리거될 λ•Œλ§ˆλ‹€ κ°€λ“œκ°€ μž‘μ„± μˆœμ„œμ— 따라 호좜되기 μ „μ˜ λͺ¨λ“  κ²½μš°μ— λ°œμƒν•©λ‹ˆλ‹€. κ°€λ“œλŠ” λΉ„λ™κΈ°μ‹μœΌλ‘œ μ‹€ν–‰ 될 수 있으며 λ„€λΉ„κ²Œμ΄μ…˜μ€ λͺ¨λ“  훅이 ν•΄κ²°λ˜κΈ° μ „κΉŒμ§€ **보λ₯˜ 쀑** 으둜 κ°„μ£Όλ©λ‹ˆλ‹€.
18+
19+
λͺ¨λ“  κ°€λ“œ κΈ°λŠ₯은 μ„Έ κ°€μ§€ μ „λ‹¬μΈμžλ₯Ό λ°›μŠ΅λ‹ˆλ‹€.
20+
21+
- **`to: 라우트`**: λŒ€μƒ [Route 객체](../api/route-object.md) 둜 μ΄λ™ν•©λ‹ˆλ‹€.
22+
23+
- **`from: 라우트`**: ν˜„μž¬ 라우트둜 μ˜€κΈ°μ „ 라우트 μž…λ‹ˆλ‹€.
24+
25+
- **`next: ν•¨μˆ˜`**: 이 ν•¨μˆ˜λŠ” **훅을 ν•΄κ²°ν•˜κΈ° μœ„ν•΄** 호좜 λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€. μ•‘μ…˜μ€ `next`에 제곡된 μ „λ‹¬μΈμžμ— 달렀 μžˆμŠ΅λ‹ˆλ‹€.
26+
27+
- **`next()`**: νŒŒμ΄ν”„λΌμΈμ˜ λ‹€μŒ ν›…μœΌλ‘œ μ΄λ™ν•˜μ‹­μ‹œμ˜€. 훅이 μ—†λŠ” 경우 λ„€λΉ„κ²Œμ΄μ…˜μ€ **승인**λ©λ‹ˆλ‹€.
28+
29+
- **`next(false)`**: ν˜„μž¬ λ„€λΉ„κ²Œμ΄μ…˜μ„ μ€‘λ‹¨ν•©λ‹ˆλ‹€. λΈŒλΌμš°μ € URL이 λ³€κ²½λ˜λ©΄(μ‚¬μš©μž λ˜λŠ” λ’€λ‘œ λ²„νŠΌμ„ 톡해 μˆ˜λ™μœΌλ‘œ 변경됨) `from`경둜의 URL둜 μž¬μ„€μ •λ©λ‹ˆλ‹€.
30+
31+
- **`next('/')` λ˜λŠ” `next({ path: '/' })`**: λ‹€λ₯Έ μœ„μΉ˜λ‘œ λ¦¬λ””λ ‰μ…˜ν•©λ‹ˆλ‹€. ν˜„μž¬ λ„€λΉ„κ²Œμ΄μ…˜μ΄ μ€‘λ‹¨λ˜κ³  μƒˆ λ„€λΉ„κ²Œμ΄μ…˜μ΄ μ‹œμž‘λ©λ‹ˆλ‹€.
32+
33+
**항상 `next` ν•¨μˆ˜λ₯Ό ν˜ΈμΆœν•˜μ‹­μ‹œμ˜€. κ·Έλ ‡μ§€ μ•ŠμœΌλ©΄ 훅이 μ ˆλŒ€ λΆˆλŸ¬μ§€μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.**
34+
35+
μ „μ—­ 훅을 등둝 ν•  μˆ˜λ„ μžˆμ§€λ§Œ, κ°€λ“œμ™€ 달리 이 훅은 `next` ν•¨μˆ˜λ₯Ό μ–»μ§€ λͺ»ν•˜λ©° λ„€λΉ„κ²Œμ΄μ…˜μ— 영ν–₯을 쀄 수 μ—†μŠ΅λ‹ˆλ‹€.
36+
37+
``` js
38+
router.afterEach((to, from) => {
39+
// ...
40+
})
41+
```
42+
43+
### 라우트 별 κ°€λ“œ
44+
45+
`beforeEnter` κ°€λ“œλ₯Ό 라우트의 μ„€μ • 객체에 직접 μ •μ˜ ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
46+
47+
``` js
48+
const router = new VueRouter({
49+
routes: [
50+
{
51+
path: '/foo',
52+
component: Foo,
53+
beforeEnter: (to, from, next) => {
54+
// ...
55+
}
56+
}
57+
]
58+
})
59+
```
60+
61+
μ΄λŸ¬ν•œ κ°€λ“œλŠ” μ „μ—­ 이전 κ°€λ“œμ™€ λ™μΌν•œ μ„œλͺ…을 κ°€μ§‘λ‹ˆλ‹€.
62+
63+
### μ»΄ν¬λ„ŒνŠΈ λ‚΄λΆ€ κ°€λ“œ
64+
65+
λ§ˆμ§€λ§‰μœΌλ‘œ `beforeRouteEnter` 와 `beforeRouteLeave`λ₯Ό μ‚¬μš©ν•˜μ—¬ 라우트 μ»΄ν¬λ„ŒνŠΈ μ•ˆμ— 라우트 λ„€λΉ„κ²Œμ΄μ…˜ κ°€λ“œλ₯Ό 직접 μ •μ˜ ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
66+
67+
``` js
68+
const Foo = {
69+
template: `...`,
70+
beforeRouteEnter (to, from, next) {
71+
// 이 μ»΄ν¬λ„ŒνŠΈλ₯Ό λ Œλ”λ§ν•˜λŠ” 라우트 μ•žμ— ν˜ΈμΆœλ©λ‹ˆλ‹€.
72+
// 이 κ°€λ“œκ°€ 호좜 될 λ•Œ 아직 μƒμ„±λ˜μ§€ μ•Šμ•˜κΈ° λ•Œλ¬Έμ—
73+
// `this` μ»΄ν¬λ„ŒνŠΈ μΈμŠ€ν„΄μŠ€μ— μ ‘κ·Ό ν•  수 μ—†μŠ΅λ‹ˆλ‹€!
74+
},
75+
beforeRouteLeave (to, from, next) {
76+
// 이 μ»΄ν¬λ„ŒνŠΈλ₯Ό λ Œλ”λ§ν•˜λŠ” λΌμš°νŠΈκ°€ μ΄μ „μœΌλ‘œ λ„€λΉ„κ²Œμ΄μ…˜ 될 λ•Œ ν˜ΈμΆœλ©λ‹ˆλ‹€.
77+
// `this` μ»΄ν¬λ„ŒνŠΈ μΈμŠ€ν„΄μŠ€μ— μ ‘κ·Ό ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
78+
}
79+
}
80+
```
81+
82+
`beforeRouteEnter` κ°€λ“œλŠ” λ„€λΉ„κ²Œμ΄μ…˜μ΄ ν™•μΈλ˜κΈ° 전에 κ°€λ“œκ°€ ν˜ΈμΆœλ˜μ–΄μ„œ μƒˆλ‘œμš΄ μ—”νŠΈλ¦¬ μ»΄ν¬λ„ŒνŠΈκ°€ 아직 μƒμ„±λ˜μ§€ μ•Šμ•˜κΈ° λ•Œλ¬Έμ— `this`에 μ ‘κ·Όν•˜μ§€ **λͺ»ν•©λ‹ˆλ‹€.**
83+
84+
κ·ΈλŸ¬λ‚˜ μ½œλ°±μ„ `next`에 μ „λ‹¬ν•˜μ—¬ μΈμŠ€ν„΄μŠ€μ— μ•‘μ„ΈμŠ€ ν•  수 μžˆμŠ΅λ‹ˆλ‹€. λ„€λΉ„κ²Œμ΄μ…˜μ΄ ν™•μΈλ˜κ³  μ»΄ν¬λ„ŒνŠΈ μΈμŠ€ν„΄μŠ€κ°€ μ½œλ°±μ— μ „λ‹¬μΈμžλ‘œ 전달 될 λ•Œ 콜백이 ν˜ΈμΆœλ©λ‹ˆλ‹€.
85+
86+
``` js
87+
beforeRouteEnter (to, from, next) {
88+
next(vm => {
89+
// `vm`을 ν†΅ν•œ μ»΄ν¬λ„ŒνŠΈ μΈμŠ€ν„΄μŠ€ μ ‘κ·Ό
90+
})
91+
}
92+
```
93+
94+
`beforeRouteLeave` μ•ˆμ—μ„œ `this`에 직접 μ ‘κ·Ό ν•  수 μžˆμŠ΅λ‹ˆλ‹€. leave κ°€λ“œλŠ” 일반적으둜 μ‚¬μš©μžκ°€ μ €μž₯ν•˜μ§€ μ•Šμ€ νŽΈμ§‘ λ‚΄μš©μ„ 두고 μ‹€μˆ˜λ‘œ 라우트λ₯Ό λ– λ‚˜λŠ” 것을 λ°©μ§€ν•˜λŠ”λ° μ‚¬μš©λ©λ‹ˆλ‹€. 탐색은 `next(false)`λ₯Ό ν˜ΈμΆœν•˜μ—¬ μ·¨μ†Œν•  수 μžˆμŠ΅λ‹ˆλ‹€.

0 commit comments

Comments
Β (0)