|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <pre>{{ currentLocation }}</pre> |
| 4 | + <section class="info"> |
| 5 | + Name: |
| 6 | + <pre id="name">{{ currentLocation.name }}</pre> |
| 7 | + </section> |
| 8 | + |
| 9 | + <section class="info"> |
| 10 | + Params: |
| 11 | + <pre id="params">{{ currentLocation.params }}</pre> |
| 12 | + </section> |
| 13 | + |
| 14 | + <section class="info"> |
| 15 | + Query: |
| 16 | + <pre id="query">{{ currentLocation.query }}</pre> |
| 17 | + </section> |
| 18 | + |
| 19 | + <section class="info"> |
| 20 | + Hash: |
| 21 | + <pre id="hash">{{ currentLocation.hash }}</pre> |
| 22 | + </section> |
| 23 | + |
| 24 | + <section class="info"> |
| 25 | + FullPath: |
| 26 | + <pre id="fullPath">{{ currentLocation.fullPath }}</pre> |
| 27 | + </section> |
| 28 | + |
| 29 | + <section class="info"> |
| 30 | + path: |
| 31 | + <pre id="path">{{ currentLocation.path }}</pre> |
| 32 | + </section> |
| 33 | + |
| 34 | + <hr /> |
| 35 | + |
| 36 | + <label> |
| 37 | + <input type="checkbox" v-model="state.cancelNextNavigation" /> Cancel Next |
| 38 | + Navigation |
| 39 | + </label> |
| 40 | + <ul> |
| 41 | + <li> |
| 42 | + <router-link to="/n/%E2%82%AC">/n/%E2%82%AC</router-link> |
| 43 | + </li> |
| 44 | + <li> |
| 45 | + <router-link :to="{ name: 'docs', params: { id: '€uro' } }" |
| 46 | + >/docs/€uro (object)</router-link |
| 47 | + > |
| 48 | + </li> |
| 49 | + <li> |
| 50 | + <router-link :to="{ path: '/', query: { currency: '€uro', é: 'e' } }" |
| 51 | + >/currency=€uro&é=e (object)</router-link |
| 52 | + > |
| 53 | + </li> |
| 54 | + <li> |
| 55 | + <router-link to="/documents/€">/n/€</router-link> |
| 56 | + </li> |
| 57 | + <li> |
| 58 | + <a href="/documents/%E2%82%AC">/documents/%E2%82%AC (force reload)</a> |
| 59 | + </li> |
| 60 | + <li> |
| 61 | + <a href="/documents/€">/documents/€ (force reload): not valid tho</a> |
| 62 | + </li> |
| 63 | + <li> |
| 64 | + <router-link to="/home">Home (redirects)</router-link> |
| 65 | + </li> |
| 66 | + <li> |
| 67 | + <router-link to="/">Home</router-link> |
| 68 | + </li> |
| 69 | + <li> |
| 70 | + <AppLink to="/">AppLink Home</AppLink> |
| 71 | + </li> |
| 72 | + <li> |
| 73 | + <router-link to="/always-redirect">/always-redirect</router-link> |
| 74 | + </li> |
| 75 | + <li> |
| 76 | + <router-link to="/children">/children</router-link> |
| 77 | + </li> |
| 78 | + <li> |
| 79 | + <router-link to="/children/alias">/children/alias</router-link> |
| 80 | + </li> |
| 81 | + <li> |
| 82 | + <router-link :to="{ name: 'default-child' }" |
| 83 | + >/children (child named)</router-link |
| 84 | + > |
| 85 | + </li> |
| 86 | + <li> |
| 87 | + <router-link :to="{ name: 'WithChildren' }" |
| 88 | + >/children (parent named)</router-link |
| 89 | + > |
| 90 | + </li> |
| 91 | + <li> |
| 92 | + <router-link to="/children/a">/children/a</router-link> |
| 93 | + </li> |
| 94 | + <li> |
| 95 | + <router-link to="/children/b">/children/b</router-link> |
| 96 | + </li> |
| 97 | + <li> |
| 98 | + <router-link to="/children/b/a2">/children/b/a2</router-link> |
| 99 | + </li> |
| 100 | + <li> |
| 101 | + <router-link to="/children/b/b2">/children/b/b2</router-link> |
| 102 | + </li> |
| 103 | + <li> |
| 104 | + <router-link to="/nested">/nested</router-link> |
| 105 | + </li> |
| 106 | + <li> |
| 107 | + <router-link to="/anidado">/anidado</router-link> |
| 108 | + </li> |
| 109 | + <li> |
| 110 | + <router-link to="/long-0">/long-0</router-link> |
| 111 | + </li> |
| 112 | + <li> |
| 113 | + <router-link to="/users/5">/users/5</router-link> |
| 114 | + </li> |
| 115 | + <li> |
| 116 | + <router-link |
| 117 | + :to="{ |
| 118 | + name: 'user', |
| 119 | + params: { id: '' + (Number(currentLocation.params.id || 0) + 1) }, |
| 120 | + }" |
| 121 | + >/users/{{ Number(currentLocation.params.id || 0) + 1 }}</router-link |
| 122 | + > |
| 123 | + </li> |
| 124 | + <li> |
| 125 | + <router-link to="/with-data">/with-data</router-link> |
| 126 | + </li> |
| 127 | + <li> |
| 128 | + <router-link to="/cant-leave">/cant-leave</router-link> |
| 129 | + </li> |
| 130 | + <li> |
| 131 | + <router-link :to="{ name: 'docs', params: { id: 'é' } }" |
| 132 | + >/docs/é</router-link |
| 133 | + > |
| 134 | + </li> |
| 135 | + <li> |
| 136 | + <router-link to="/rep">/rep</router-link> |
| 137 | + </li> |
| 138 | + <li> |
| 139 | + <router-link to="/rep/a">/rep/a</router-link> |
| 140 | + </li> |
| 141 | + <li> |
| 142 | + <router-link to="/rep/a/b">/rep/a/b</router-link> |
| 143 | + </li> |
| 144 | + <li> |
| 145 | + <router-link to="/parent/1">/parent/1</router-link> |
| 146 | + </li> |
| 147 | + <li> |
| 148 | + <router-link to="/p/1">/p/1</router-link> |
| 149 | + </li> |
| 150 | + <li> |
| 151 | + <router-link to="/parent/1/as-absolute-a" |
| 152 | + >/parent/1/as-absolute-a</router-link |
| 153 | + > |
| 154 | + </li> |
| 155 | + <li> |
| 156 | + <router-link to="/p/1/as-absolute-a">/p/1/as-absolute-a</router-link> |
| 157 | + </li> |
| 158 | + <li> |
| 159 | + <router-link to="/p_1/absolute-a">/p_1/absolute-a</router-link> |
| 160 | + </li> |
| 161 | + </ul> |
| 162 | + <button @click="toggleViewName">Toggle view</button> |
| 163 | + <Suspense> |
| 164 | + <template #default> |
| 165 | + <router-view :name="viewName" v-slot="{ Component, route }"> |
| 166 | + <transition |
| 167 | + :name="route.meta.transition || 'fade'" |
| 168 | + mode="out-in" |
| 169 | + @before-enter="flushWaiter" |
| 170 | + @before-leave="setupWaiter" |
| 171 | + > |
| 172 | + <keep-alive> |
| 173 | + <component |
| 174 | + :is="Component" |
| 175 | + :key="route.name === 'repeat' ? route.path : undefined" |
| 176 | + /> |
| 177 | + </keep-alive> |
| 178 | + </transition> |
| 179 | + </router-view> |
| 180 | + </template> |
| 181 | + <template #fallback> Loading... </template> |
| 182 | + </Suspense> |
| 183 | + </div> |
| 184 | +</template> |
| 185 | + |
| 186 | +<script> |
| 187 | +import { defineComponent, inject, computed, ref } from 'vue' |
| 188 | +import { scrollWaiter } from './scrollWaiter' |
| 189 | +import { useLink, useRoute } from 'vue-router' |
| 190 | +import AppLink from './AppLink.vue' |
| 191 | +
|
| 192 | +export default defineComponent({ |
| 193 | + name: 'App', |
| 194 | + components: { AppLink }, |
| 195 | + setup() { |
| 196 | + const route = useRoute() |
| 197 | + const state = inject('state') |
| 198 | + const viewName = ref('default') |
| 199 | +
|
| 200 | + useLink({ to: '/' }) |
| 201 | + useLink({ to: '/documents/hello' }) |
| 202 | + useLink({ to: '/children' }) |
| 203 | +
|
| 204 | + const currentLocation = computed(() => { |
| 205 | + const { matched, ...rest } = route |
| 206 | + return rest |
| 207 | + }) |
| 208 | +
|
| 209 | + function flushWaiter() { |
| 210 | + scrollWaiter.flush() |
| 211 | + } |
| 212 | + function setupWaiter() { |
| 213 | + scrollWaiter.add() |
| 214 | + } |
| 215 | +
|
| 216 | + const nextUserLink = computed( |
| 217 | + () => '/users/' + String((Number(route.value.params.id) || 0) + 1) |
| 218 | + ) |
| 219 | +
|
| 220 | + return { |
| 221 | + currentLocation, |
| 222 | + nextUserLink, |
| 223 | + state, |
| 224 | + flushWaiter, |
| 225 | + setupWaiter, |
| 226 | + viewName, |
| 227 | + toggleViewName() { |
| 228 | + viewName.value = viewName.value === 'default' ? 'other' : 'default' |
| 229 | + }, |
| 230 | + } |
| 231 | + }, |
| 232 | +}) |
| 233 | +</script> |
0 commit comments