From dd8bf6cf48db352cef72f419a14d1540818eb6ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B1=E6=98=AF=E5=96=9C=E6=AC=A2=E9=99=88=E7=B2=92?= Date: Wed, 24 Mar 2021 17:31:27 +0800 Subject: [PATCH] feat(warn): throws if history is missing (#844) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 成仕伟 Co-authored-by: Eduardo San Martin Morote Co-authored-by: Eduardo San Martin Morote --- __tests__/router.spec.ts | 7 +++++++ src/router.ts | 5 +++++ 2 files changed, 12 insertions(+) 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>()