Skip to content

Commit f6b4a65

Browse files
committed
Warn about invalid location sooner
Fixes #613
1 parent 0979d39 commit f6b4a65

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

modules/utils/createRouter.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,20 @@ function createRouter(options) {
154154
nextState = {};
155155
}
156156

157+
if (typeof location === 'string') {
158+
warning(
159+
!canUseDOM || process.env.NODE_ENV === 'test',
160+
'You should not use a static location in a DOM environment because ' +
161+
'the router will not be kept in sync with the current URL'
162+
);
163+
} else {
164+
invariant(
165+
canUseDOM,
166+
'You cannot use %s without a DOM',
167+
location
168+
);
169+
}
170+
157171
// Automatically fall back to full page refreshes in
158172
// browsers that don't support the HTML history API.
159173
if (location === HistoryLocation && !supportsHistory())
@@ -388,21 +402,8 @@ function createRouter(options) {
388402
};
389403

390404
if (typeof location === 'string') {
391-
warning(
392-
!canUseDOM || process.env.NODE_ENV === 'test',
393-
'You should not use a static location in a DOM environment because ' +
394-
'the router will not be kept in sync with the current URL'
395-
);
396-
397-
// Dispatch the location.
398405
router.dispatch(location, null, dispatchHandler);
399406
} else {
400-
invariant(
401-
canUseDOM,
402-
'You cannot use %s in a non-DOM environment',
403-
location
404-
);
405-
406407
// Listen for changes to the location.
407408
var changeListener = function (change) {
408409
router.dispatch(change.path, change.type, dispatchHandler);

0 commit comments

Comments
 (0)