import { createApp } from 'vue'
import { router, routerHistory } from './router'
import { globalState } from './store'
-import { RouterPlugin } from '../src'
import App from './App.vue'
declare global {
const app = createApp(App)
app.provide('state', globalState)
-app.use(RouterPlugin, router)
+app.use(router)
app.mount('#app')
import { createRouter, Router } from './router'
-import { App, Ref, InjectionKey } from 'vue'
+import { Ref, InjectionKey } from 'vue'
import createHistory from './history/html5'
import createMemoryHistory from './history/memory'
import createHashHistory from './history/hash'
-import { View } from './components/View'
-import Link from './components/Link'
import {
RouteLocationNormalized,
START_LOCATION_NORMALIZED as START_LOCATION,
function inject(name: 'route'): Ref<RouteLocationNormalized>
}
-export function RouterPlugin(app: App, router: Router) {
- // TODO: remove as any
- app.component('RouterLink', Link as any)
- app.component('RouterView', View as any)
-
- let started = false
- // TODO: can we use something that isn't a mixin?
- app.mixin({
- beforeCreate() {
- if (!started) {
- // TODO: this initial navigation is only necessary on client, on server it doesn't make sense
- // because it will create an extra unecessary navigation and could lead to problems
- router.push(router.history.location).catch(err => {
- console.error('Unhandled error', err)
- })
- started = true
- }
- },
- })
-
- // TODO: merge strats?
-
- app.provide('router', router)
- app.provide('route', router.currentRoute)
-}
-
export {
createHistory,
createMemoryHistory,
import { useCallbacks } from './utils/callbacks'
import { encodeParam } from './utils/encoding'
import { decode } from './utils/encoding'
-import { ref, Ref, markNonReactive, nextTick } from 'vue'
+import { ref, Ref, markNonReactive, nextTick, App } from 'vue'
import { RouteRecordMatched } from './matcher/types'
+import Link from './components/Link'
+import { View } from './components/View'
type ErrorHandler = (error: any) => any
// resolve, reject arguments of Promise constructor
// TODO: also return a ListenerRemover
onError(handler: ErrorHandler): void
isReady(): Promise<void>
+
+ install(app: App): void
}
const isClient = typeof window !== 'undefined'
isReady,
history,
+ install(app: App) {
+ applyRouterPlugin(app, this)
+ },
}
return router
}
+
+function applyRouterPlugin(app: App, router: Router) {
+ // TODO: remove as any
+ app.component('RouterLink', Link as any)
+ app.component('RouterView', View as any)
+
+ let started = false
+ // TODO: can we use something that isn't a mixin?
+ app.mixin({
+ beforeCreate() {
+ if (!started) {
+ // TODO: this initial navigation is only necessary on client, on server it doesn't make sense
+ // because it will create an extra unecessary navigation and could lead to problems
+ router.push(router.history.location).catch(err => {
+ console.error('Unhandled error', err)
+ })
+ started = true
+ }
+ },
+ })
+
+ // TODO: merge strats?
+ app.provide('router', router)
+ app.provide('route', router.currentRoute)
+}