diff --git a/__tests__/router.spec.ts b/__tests__/router.spec.ts index a1303e267..e8f49c91b 100644 --- a/__tests__/router.spec.ts +++ b/__tests__/router.spec.ts @@ -93,6 +93,13 @@ describe('Router', () => { createDom() }) + it('fails if history option is missing', () => { + // @ts-ignore + expect(() => createRouter({ routes })).toThrowError( + 'Provide the "history" option' + ) + }) + it('starts at START_LOCATION', () => { const history = createMemoryHistory() const router = createRouter({ history, routes }) diff --git a/src/router.ts b/src/router.ts index 14158f6d4..c9a8a07e2 100644 --- a/src/router.ts +++ b/src/router.ts @@ -343,6 +343,11 @@ export function createRouter(options: RouterOptions): Router { let parseQuery = options.parseQuery || originalParseQuery let stringifyQuery = options.stringifyQuery || originalStringifyQuery let routerHistory = options.history + if (__DEV__ && !routerHistory) + throw new Error( + 'Provide the "history" option when calling "createRouter()":' + + ' https://next.router.vuejs.org/api/#history.' + ) const beforeGuards = useCallbacks>() const beforeResolveGuards = useCallbacks>()