From: 就是喜欢陈粒 Date: Wed, 24 Mar 2021 09:31:27 +0000 (+0800) Subject: feat(warn): throws if history is missing (#844) X-Git-Tag: v4.0.6~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd8bf6cf48db352cef72f419a14d1540818eb6ff;p=thirdparty%2Fvuejs%2Frouter.git feat(warn): throws if history is missing (#844) Co-authored-by: 成仕伟 Co-authored-by: Eduardo San Martin Morote Co-authored-by: Eduardo San Martin Morote --- diff --git a/__tests__/router.spec.ts b/__tests__/router.spec.ts index a1303e26..e8f49c91 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 14158f6d..c9a8a07e 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>()