]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
feat(warn): throws if history is missing (#844)
author就是喜欢陈粒 <cheng_deeplove@163.com>
Wed, 24 Mar 2021 09:31:27 +0000 (17:31 +0800)
committerGitHub <noreply@github.com>
Wed, 24 Mar 2021 09:31:27 +0000 (10:31 +0100)
Co-authored-by: 成仕伟 <chengsw@heywhale.com>
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
Co-authored-by: Eduardo San Martin Morote <posva13@gmail.com>
__tests__/router.spec.ts
src/router.ts

index a1303e267bb694af9ae21c70a0e559b742852b53..e8f49c91bb991af8aca87351520852d44814ff88 100644 (file)
@@ -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 })
index 14158f6d4933b20204ce03b0248819c3f7aea89b..c9a8a07e2a9f5ae15825f2e933f265408fb0daf2 100644 (file)
@@ -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<NavigationGuardWithThis<undefined>>()
   const beforeResolveGuards = useCallbacks<NavigationGuardWithThis<undefined>>()