Skip to content

Commit dd8bf6c

Browse files
Lucian-4a25成仕伟posva
authored
feat(warn): throws if history is missing (vuejs#844)
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>
1 parent 178abbc commit dd8bf6c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

__tests__/router.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ describe('Router', () => {
9393
createDom()
9494
})
9595

96+
it('fails if history option is missing', () => {
97+
// @ts-ignore
98+
expect(() => createRouter({ routes })).toThrowError(
99+
'Provide the "history" option'
100+
)
101+
})
102+
96103
it('starts at START_LOCATION', () => {
97104
const history = createMemoryHistory()
98105
const router = createRouter({ history, routes })

src/router.ts

+5
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ export function createRouter(options: RouterOptions): Router {
343343
let parseQuery = options.parseQuery || originalParseQuery
344344
let stringifyQuery = options.stringifyQuery || originalStringifyQuery
345345
let routerHistory = options.history
346+
if (__DEV__ && !routerHistory)
347+
throw new Error(
348+
'Provide the "history" option when calling "createRouter()":' +
349+
' https://next.router.vuejs.org/api/#history.'
350+
)
346351

347352
const beforeGuards = useCallbacks<NavigationGuardWithThis<undefined>>()
348353
const beforeResolveGuards = useCallbacks<NavigationGuardWithThis<undefined>>()

0 commit comments

Comments
 (0)