Slide 1

Slide 1 text

Nozomu Ikuta 2020/09/18 Vue Router Next ҙ֎ͱޠΒΕͳ͍ Vue 3 ࣌୅ͷϧʔςΟϯά

Slide 2

Slide 2 text

Who I am ඵͰΘ͔Δϫλγ • ੜా๬ / Nozomu Ikuta • Verdaࣨ UI Engineering νʔϜ /
 UIT Dev 2 νʔϜ • Twitter: @NozomuIkuta

Slide 3

Slide 3 text

Why Talk about Vue Router ࣮͸େܕΞοϓσʔτ • Vue 3 ͸ ΋ͪΖΜΈͳ͞Μڵຯ௡ʑ • Vuex 4 ͸ state ͷ Type Support Ͱ TypeScripter ͕׻ت • Vue Router 4 ͸Έͳ͞Μڵຯͳ͠…? • ࣮͸ Vue 3 / Vuex 4 ฒΈʹັྗతͳΞοϓσʔτ͕͋Δ͜ͱΛ఻͍͑ͨ • ʮVue ࡾດʯ͔ͩΒͦ͜

Slide 4

Slide 4 text

Router Factory `new` ͡Όͳ͍ͷ͕৽͍͠ • Vue 3 ΍ Vuex 4 ʹͳΒ͍ `new VueRouter()` Ͱ͸ͳ͘ `createRouter()` ʹมߋ • `history ` Φϓγϣϯ΋ؔ਺Λ౉͢Α͏ʹͳͬͯ tree-shakable ʹ

Slide 5

Slide 5 text

Route Composition Function จࣈ௨ΓʮϧʔτΛ࢖͏ʯ • `setup()` ؔ਺Ͱ͸ `this.$route` ͕࢖༻ෆՄ • ୅ΘΓʹ `useRoute()` ίϯϙδγϣϯؔ਺Λ࢖ͬͯ࿈ܞ

Slide 6

Slide 6 text

Route Meta Merge ΋͏୳͞ͳ͍͍ͯ͘ • ࢠϧʔτͷ `meta` ͸਌ͷ `meta` ͱ shallow merge ͞ΕΔΑ͏ʹมߋ • ਌ route ͷ access control ϑϥάΛࢠ route Ͱ΋௚઀ࢀরͰ͖Δʂ

Slide 7

Slide 7 text

Router Link Scoped Slot Ϣʔɾϋϒɾίϯτϩʔϧ • Default slot ͸Ҿ͖ଓ͖݈ࡏ • `tag` prop ͱ `event` prop ͸ഇࢭ • `custom` prop + scoped slot ͰϑϧΧελϜʂ • Default scoped slot Ͱ `slotProps` Λड͚औͬͯ
 custom component ΋׬શ੍ޚʂ

Slide 8

Slide 8 text

Router Link Active ࢥͬͨ௨ΓʹΞΫςΟϒʹ • active ͔Ͳ͏͔ͷ൑ఆج४͕ΑΓ௚؍తʹʂʢৄࡉ͸ׂѪ ʣ • `exact` prop ͸ഇࢭ • ΤΠϦΞε΋ active ͷ൑ఆର৅ʹ • URL ΫΤϦ͸ active ൑ఆͷର৅֎ʹʢηϧϑαʔϏεʹมߋʣ

Slide 9

Slide 9 text

Router View Scoped Slot • Router View ʹ default scoped slot ͕௥Ճ • Slot ͷதͰ v-if/v-else ͢Ε͹ɺNOT FOUND ϖʔδʹԠ༻Ͱ͖Δ σϑΥϧτɾϏϡʔ

Slide 10

Slide 10 text

Router View Route Prop • Router View ʹ `route` prop ͕௥Ճ • Router View ʹදࣔ͢Δ route Λ໌ࣔతʹࢦఆͰ͖ΔΑ͏ʹ • ผͷϖʔδΛදࣔͨ͠·· URL ΛϞʔμϧ༻ʹมߋͰ͖Δ • Ϟʔμϧදࣔঢ়ଶΛωΠςΟϒʹώετϦʔʹ࢒ͤΔ ϋοΫ͠ͳͯ͘Α͘ͳΓ·ͨ͠

Slide 11

Slide 11 text

ඦฉ͸Ұݟʹ೗͔ͣ ʢDEMOʣ

Slide 12

Slide 12 text

And More! ਖ਼௚ɺ10෼͡Όແཧ • ಈతͳ route ͷߋ৽͕Մೳʹ (`addRoute()`, `removeRoute()`) • ΑΓ promise-based ͳ navigation ʹ • Navigation guard ͷ `next()` ͕ഇࢭ • Navigation failure ͷछྨ͕ΑΓ໌֬ʹ • Router View ͱ Keep Alive / Transition ͱͷซ༻ํ๏͕มߋ • `scrollBehavior()` ؔ਺͕ΑΓωΠςΟϒ API ʹۙ͘ɺศརʹ

Slide 13

Slide 13 text

References ࢀߟࢿྉ • https://github.com/vuejs/rfcs/blob/master/active-rfcs/0036-router-view-route-prop.md • https://github.com/vuejs/rfcs/blob/master/active-rfcs/0021-router-link-scoped-slot.md • https://github.com/vuejs/rfcs/blob/master/active-rfcs/0022-router-merge-meta-routelocation.md • https://github.com/vuejs/rfcs/blob/master/active-rfcs/0028-router-active-link.md • https://github.com/vuejs/rfcs/blob/master/active-rfcs/0029-router-dynamic-routing.md • https://github.com/vuejs/rfcs/blob/master/active-rfcs/0033-router-navigation-failures.md • https://github.com/vuejs/rfcs/blob/master/active-rfcs/0034-router-view-keep-alive-transitions.md • https://github.com/vuejs/rfcs/blob/master/active-rfcs/0035-router-scroll-position.md • https://github.com/vuejs/rfcs/blob/master/active-rfcs/0036-router-view-route-prop.md • https://github.com/vuejs/rfcs/blob/master/active-rfcs/0037-router-return-guards.md

Slide 14

Slide 14 text

Thank You