Skip to content

Commit

Permalink
feat(warn): throws if history is missing (#844)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
4 people committed Mar 24, 2021
1 parent 178abbc commit dd8bf6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions __tests__/router.spec.ts
Expand Up @@ -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 })
Expand Down
5 changes: 5 additions & 0 deletions src/router.ts
Expand Up @@ -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>>()
Expand Down

0 comments on commit dd8bf6c

Please sign in to comment.