vuejs-rails 2.0.5 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d64e5ab7056e1c860447c1874d5a97648ecb2eec
4
- data.tar.gz: f5d84b069fb1a787af4eff100a60b50b17a0fe90
3
+ metadata.gz: b14ac4b1d7d9e883b4206f5c7559d9be7ab40005
4
+ data.tar.gz: 80d3709c219eafee3a329dbace290b31091bd656
5
5
  SHA512:
6
- metadata.gz: ce1f4729d0b911ab1bac8e097f2f7d59587acb2fa08c8045accef1bb2ea9d31dd789e504380ec7bdbf9e65893de98cc09a9833deca9cdf07af83de2758c7ed72
7
- data.tar.gz: 6b3f279a1f8d1e70be1188cacfe4efb3a7923773e804617659e8d3abe5c608b4379ffcae6e71ad28262b7f53ee2a84fd5f55b592211a499cda7423b7dedd6e77
6
+ metadata.gz: 11de3fcb8ffba8780d5168d486770d1f69d84efdef0753c59ad032fb7023299f82e1aeb53df33cacb8729951342aaf379d6249a09afc8b4bcb13d18e204e0c4c
7
+ data.tar.gz: 537fa5971ef546f6c40f2b3b44a9f99389b9fa142720bfd029f702bb0045a2ce74173419aef1302117dd1ade16b316b804788156cb9e0712388869e0299d982c
data/Readme.md CHANGED
@@ -9,8 +9,8 @@ Rails 3.1+ asset-pipeline gem to provide Vue.js
9
9
 
10
10
  ### Package Versions
11
11
 
12
- - vue v2.0.3
13
- - vue-router v2.0.1
12
+ - vue v2.0.8
13
+ - vue-router v2.0.3
14
14
  - vue-resource v1.0.3
15
15
 
16
16
  ### Setup
@@ -1,5 +1,5 @@
1
1
  module Vue
2
2
  module Rails
3
- VERSION = '2.0.5'
3
+ VERSION = '2.0.8'
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  /**
2
- * vue-router v2.0.1
2
+ * vue-router v2.0.3
3
3
  * (c) 2016 Evan You
4
4
  * @license MIT
5
5
  */
@@ -57,6 +57,9 @@ var View = {
57
57
  hooks.init = function (vnode) {
58
58
  matched.instances[name] = vnode.child
59
59
  }
60
+ hooks.prepatch = function (oldVnode, vnode) {
61
+ matched.instances[name] = vnode.child
62
+ }
60
63
  hooks.destroy = function (vnode) {
61
64
  if (matched.instances[name] === vnode.child) {
62
65
  matched.instances[name] = undefined
@@ -183,7 +186,7 @@ function resolveQuery (
183
186
  }
184
187
 
185
188
  function parseQuery (query) {
186
- var res = Object.create(null)
189
+ var res = {}
187
190
 
188
191
  query = query.trim().replace(/^(\?|#|&)/, '')
189
192
 
@@ -325,7 +328,7 @@ function isObjectEqual (a, b) {
325
328
 
326
329
  function isIncludedRoute (current, target) {
327
330
  return (
328
- current.path.indexOf(target.path) === 0 &&
331
+ current.path.indexOf(target.path.replace(/\/$/, '')) === 0 &&
329
332
  (!target.hash || current.hash === target.hash) &&
330
333
  queryIncludes(current.query, target.query)
331
334
  )
@@ -398,10 +401,10 @@ var Link = {
398
401
  var router = this.$router
399
402
  var current = this.$route
400
403
  var to = normalizeLocation(this.to, current, this.append)
401
- var resolved = router.match(to)
404
+ var resolved = router.match(to, current)
402
405
  var fullPath = resolved.redirectedFrom || resolved.fullPath
403
406
  var base = router.history.base
404
- var href = base ? cleanPath(base + fullPath) : fullPath
407
+ var href = createHref(base, fullPath, router.mode)
405
408
  var classes = {}
406
409
  var activeClass = this.activeClass || router.options.linkActiveClass || 'router-link-active'
407
410
  var compareTarget = to.path ? createRoute(null, to) : resolved
@@ -420,6 +423,11 @@ var Link = {
420
423
  // don't redirect on right click
421
424
  /* istanbul ignore if */
422
425
  if (e.button !== 0) { return }
426
+ // don't redirect if `target="_blank"`
427
+ /* istanbul ignore if */
428
+ var target = e.target.getAttribute('target')
429
+ if (/\b_blank\b/i.test(target)) { return }
430
+
423
431
  e.preventDefault()
424
432
  if (this$1.replace) {
425
433
  router.replace(to)
@@ -440,9 +448,12 @@ var Link = {
440
448
  // find the first <a> child and apply listener and href
441
449
  var a = findAnchor(this.$slots.default)
442
450
  if (a) {
443
- var aData = a.data || (a.data = {})
451
+ // in case the <a> is a static node
452
+ a.isStatic = false
453
+ var extend = _Vue.util.extend
454
+ var aData = a.data = extend({}, a.data)
444
455
  aData.on = on
445
- var aAttrs = aData.attrs || (aData.attrs = {})
456
+ var aAttrs = a.data.attrs = extend({}, a.data.attrs)
446
457
  aAttrs.href = href
447
458
  } else {
448
459
  // doesn't have <a> child, apply listener to self
@@ -469,10 +480,19 @@ function findAnchor (children) {
469
480
  }
470
481
  }
471
482
 
483
+ function createHref (base, fullPath, mode) {
484
+ var path = mode === 'hash' ? '/#' + fullPath : fullPath
485
+ return base ? cleanPath(base + path) : path
486
+ }
487
+
488
+ var _Vue
489
+
472
490
  function install (Vue) {
473
491
  if (install.installed) { return }
474
492
  install.installed = true
475
493
 
494
+ _Vue = Vue
495
+
476
496
  Object.defineProperty(Vue.prototype, '$router', {
477
497
  get: function get () { return this.$root._router }
478
498
  })
@@ -493,6 +513,10 @@ function install (Vue) {
493
513
 
494
514
  Vue.component('router-view', View)
495
515
  Vue.component('router-link', Link)
516
+
517
+ var strats = Vue.config.optionMergeStrategies
518
+ // use the same hook merging strategy for route hooks
519
+ strats.beforeRouteEnter = strats.beforeRouteLeave = strats.created
496
520
  }
497
521
 
498
522
  var __moduleExports = Array.isArray || function (arr) {
@@ -531,14 +555,16 @@ var PATH_REGEXP = new RegExp([
531
555
  /**
532
556
  * Parse a string for the raw tokens.
533
557
  *
534
- * @param {string} str
558
+ * @param {string} str
559
+ * @param {Object=} options
535
560
  * @return {!Array}
536
561
  */
537
- function parse (str) {
562
+ function parse (str, options) {
538
563
  var tokens = []
539
564
  var key = 0
540
565
  var index = 0
541
566
  var path = ''
567
+ var defaultDelimiter = options && options.delimiter || '/'
542
568
  var res
543
569
 
544
570
  while ((res = PATH_REGEXP.exec(str)) != null) {
@@ -571,8 +597,8 @@ function parse (str) {
571
597
  var partial = prefix != null && next != null && next !== prefix
572
598
  var repeat = modifier === '+' || modifier === '*'
573
599
  var optional = modifier === '?' || modifier === '*'
574
- var delimiter = res[2] || '/'
575
- var pattern = capture || group || (asterisk ? '.*' : '[^' + delimiter + ']+?')
600
+ var delimiter = res[2] || defaultDelimiter
601
+ var pattern = capture || group
576
602
 
577
603
  tokens.push({
578
604
  name: name || key++,
@@ -582,7 +608,7 @@ function parse (str) {
582
608
  repeat: repeat,
583
609
  partial: partial,
584
610
  asterisk: !!asterisk,
585
- pattern: escapeGroup(pattern)
611
+ pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?')
586
612
  })
587
613
  }
588
614
 
@@ -603,10 +629,11 @@ function parse (str) {
603
629
  * Compile a string to a template function for the path.
604
630
  *
605
631
  * @param {string} str
632
+ * @param {Object=} options
606
633
  * @return {!function(Object=, Object=)}
607
634
  */
608
- function compile (str) {
609
- return tokensToFunction(parse(str))
635
+ function compile (str, options) {
636
+ return tokensToFunction(parse(str, options))
610
637
  }
611
638
 
612
639
  /**
@@ -817,34 +844,28 @@ function arrayToRegexp (path, keys, options) {
817
844
  * @return {!RegExp}
818
845
  */
819
846
  function stringToRegexp (path, keys, options) {
820
- var tokens = parse(path)
821
- var re = tokensToRegExp(tokens, options)
822
-
823
- // Attach keys back to the regexp.
824
- for (var i = 0; i < tokens.length; i++) {
825
- if (typeof tokens[i] !== 'string') {
826
- keys.push(tokens[i])
827
- }
828
- }
829
-
830
- return attachKeys(re, keys)
847
+ return tokensToRegExp(parse(path, options), keys, options)
831
848
  }
832
849
 
833
850
  /**
834
851
  * Expose a function for taking tokens and returning a RegExp.
835
852
  *
836
- * @param {!Array} tokens
837
- * @param {Object=} options
853
+ * @param {!Array} tokens
854
+ * @param {(Array|Object)=} keys
855
+ * @param {Object=} options
838
856
  * @return {!RegExp}
839
857
  */
840
- function tokensToRegExp (tokens, options) {
858
+ function tokensToRegExp (tokens, keys, options) {
859
+ if (!isarray(keys)) {
860
+ options = /** @type {!Object} */ (keys || options)
861
+ keys = []
862
+ }
863
+
841
864
  options = options || {}
842
865
 
843
866
  var strict = options.strict
844
867
  var end = options.end !== false
845
868
  var route = ''
846
- var lastToken = tokens[tokens.length - 1]
847
- var endsWithSlash = typeof lastToken === 'string' && /\/$/.test(lastToken)
848
869
 
849
870
  // Iterate over the tokens and create our regexp string.
850
871
  for (var i = 0; i < tokens.length; i++) {
@@ -856,6 +877,8 @@ function tokensToRegExp (tokens, options) {
856
877
  var prefix = escapeString(token.prefix)
857
878
  var capture = '(?:' + token.pattern + ')'
858
879
 
880
+ keys.push(token)
881
+
859
882
  if (token.repeat) {
860
883
  capture += '(?:' + prefix + capture + ')*'
861
884
  }
@@ -874,12 +897,15 @@ function tokensToRegExp (tokens, options) {
874
897
  }
875
898
  }
876
899
 
900
+ var delimiter = escapeString(options.delimiter || '/')
901
+ var endsWithDelimiter = route.slice(-delimiter.length) === delimiter
902
+
877
903
  // In non-strict mode we allow a slash at the end of match. If the path to
878
904
  // match already ends with a slash, we remove it for consistency. The slash
879
905
  // is valid at the end of a path match, not in the middle. This is important
880
906
  // in non-ending mode, where "/test/" shouldn't match "/test//route".
881
907
  if (!strict) {
882
- route = (endsWithSlash ? route.slice(0, -2) : route) + '(?:\\/(?=$))?'
908
+ route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?'
883
909
  }
884
910
 
885
911
  if (end) {
@@ -887,10 +913,10 @@ function tokensToRegExp (tokens, options) {
887
913
  } else {
888
914
  // In non-ending mode, we need the capturing groups to match as much as
889
915
  // possible by using a positive lookahead to the end or next path segment.
890
- route += strict && endsWithSlash ? '' : '(?=\\/|$)'
916
+ route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)'
891
917
  }
892
918
 
893
- return new RegExp('^' + route, flags(options))
919
+ return attachKeys(new RegExp('^' + route, flags(options)), keys)
894
920
  }
895
921
 
896
922
  /**
@@ -906,15 +932,13 @@ function tokensToRegExp (tokens, options) {
906
932
  * @return {!RegExp}
907
933
  */
908
934
  function pathToRegexp (path, keys, options) {
909
- keys = keys || []
910
-
911
935
  if (!isarray(keys)) {
912
- options = /** @type {!Object} */ (keys)
936
+ options = /** @type {!Object} */ (keys || options)
913
937
  keys = []
914
- } else if (!options) {
915
- options = {}
916
938
  }
917
939
 
940
+ options = options || {}
941
+
918
942
  if (path instanceof RegExp) {
919
943
  return regexpToRegexp(path, /** @type {!Array} */ (keys))
920
944
  }
@@ -980,7 +1004,7 @@ function addRouteRecord (
980
1004
  })
981
1005
  }
982
1006
 
983
- if (route.alias) {
1007
+ if (route.alias !== undefined) {
984
1008
  if (Array.isArray(route.alias)) {
985
1009
  route.alias.forEach(function (alias) {
986
1010
  addRouteRecord(pathMap, nameMap, { path: alias }, parent, record.path)
@@ -991,7 +1015,13 @@ function addRouteRecord (
991
1015
  }
992
1016
 
993
1017
  pathMap[record.path] = record
994
- if (name) { nameMap[name] = record }
1018
+ if (name) {
1019
+ if (!nameMap[name]) {
1020
+ nameMap[name] = record
1021
+ } else {
1022
+ warn(false, ("Duplicate named routes definition: { name: \"" + name + "\", path: \"" + (record.path) + "\" }"))
1023
+ }
1024
+ }
995
1025
  }
996
1026
 
997
1027
  function normalizePath (path, parent) {
@@ -1005,6 +1035,8 @@ function normalizePath (path, parent) {
1005
1035
 
1006
1036
  var regexpCache = Object.create(null)
1007
1037
 
1038
+ var regexpParamsCache = Object.create(null)
1039
+
1008
1040
  var regexpCompileCache = Object.create(null)
1009
1041
 
1010
1042
  function createMatcher (routes) {
@@ -1022,6 +1054,20 @@ function createMatcher (routes) {
1022
1054
 
1023
1055
  if (name) {
1024
1056
  var record = nameMap[name]
1057
+ var paramNames = getParams(record.path)
1058
+
1059
+ if (typeof location.params !== 'object') {
1060
+ location.params = {}
1061
+ }
1062
+
1063
+ if (currentRoute && typeof currentRoute.params === 'object') {
1064
+ for (var key in currentRoute.params) {
1065
+ if (!(key in location.params) && paramNames.indexOf(key) > -1) {
1066
+ location.params[key] = currentRoute.params[key]
1067
+ }
1068
+ }
1069
+ }
1070
+
1025
1071
  if (record) {
1026
1072
  location.path = fillParams(record.path, location.params, ("named route \"" + name + "\""))
1027
1073
  return _createRoute(record, location, redirectedFrom)
@@ -1131,13 +1177,10 @@ function createMatcher (routes) {
1131
1177
  return match
1132
1178
  }
1133
1179
 
1134
- function matchRoute (
1135
- path,
1136
- params,
1137
- pathname
1138
- ) {
1139
- var keys, regexp
1180
+ function getRouteRegex (path) {
1140
1181
  var hit = regexpCache[path]
1182
+ var keys, regexp
1183
+
1141
1184
  if (hit) {
1142
1185
  keys = hit.keys
1143
1186
  regexp = hit.regexp
@@ -1146,6 +1189,18 @@ function matchRoute (
1146
1189
  regexp = index(path, keys)
1147
1190
  regexpCache[path] = { keys: keys, regexp: regexp }
1148
1191
  }
1192
+
1193
+ return { keys: keys, regexp: regexp }
1194
+ }
1195
+
1196
+ function matchRoute (
1197
+ path,
1198
+ params,
1199
+ pathname
1200
+ ) {
1201
+ var ref = getRouteRegex(path);
1202
+ var regexp = ref.regexp;
1203
+ var keys = ref.keys;
1149
1204
  var m = pathname.match(regexp)
1150
1205
 
1151
1206
  if (!m) {
@@ -1179,6 +1234,11 @@ function fillParams (
1179
1234
  }
1180
1235
  }
1181
1236
 
1237
+ function getParams (path) {
1238
+ return regexpParamsCache[path] ||
1239
+ (regexpParamsCache[path] = getRouteRegex(path).keys.map(function (key) { return key.name; }))
1240
+ }
1241
+
1182
1242
  function resolveRecordPath (path, record) {
1183
1243
  return resolvePath(path, record.parent ? record.parent.path : '/', true)
1184
1244
  }
@@ -1277,7 +1337,7 @@ History.prototype.confirmTransition = function confirmTransition (route, cb) {
1277
1337
  hook(route, current, function (to) {
1278
1338
  if (to === false) {
1279
1339
  // next(false) -> abort navigation, ensure current URL
1280
- this$1.ensureURL()
1340
+ this$1.ensureURL(true)
1281
1341
  } else if (typeof to === 'string' || typeof to === 'object') {
1282
1342
  // next('/') or next({ path: '/' }) -> redirect
1283
1343
  this$1.push(to)
@@ -1351,15 +1411,35 @@ function resolveQueue (
1351
1411
  }
1352
1412
  }
1353
1413
 
1414
+ function extractGuard (
1415
+ def,
1416
+ key
1417
+ ) {
1418
+ if (typeof def !== 'function') {
1419
+ // extend now so that global mixins are applied.
1420
+ def = _Vue.extend(def)
1421
+ }
1422
+ return def.options[key]
1423
+ }
1424
+
1354
1425
  function extractLeaveGuards (matched) {
1355
- return flatMapComponents(matched, function (def, instance) {
1356
- var guard = def && def.beforeRouteLeave
1426
+ return flatten(flatMapComponents(matched, function (def, instance) {
1427
+ var guard = extractGuard(def, 'beforeRouteLeave')
1357
1428
  if (guard) {
1358
- return function routeLeaveGuard () {
1359
- return guard.apply(instance, arguments)
1360
- }
1429
+ return Array.isArray(guard)
1430
+ ? guard.map(function (guard) { return wrapLeaveGuard(guard, instance); })
1431
+ : wrapLeaveGuard(guard, instance)
1361
1432
  }
1362
- }).reverse()
1433
+ }).reverse())
1434
+ }
1435
+
1436
+ function wrapLeaveGuard (
1437
+ guard,
1438
+ instance
1439
+ ) {
1440
+ return function routeLeaveGuard () {
1441
+ return guard.apply(instance, arguments)
1442
+ }
1363
1443
  }
1364
1444
 
1365
1445
  function extractEnterGuards (
@@ -1367,29 +1447,46 @@ function extractEnterGuards (
1367
1447
  cbs,
1368
1448
  isValid
1369
1449
  ) {
1370
- return flatMapComponents(matched, function (def, _, match, key) {
1371
- var guard = def && def.beforeRouteEnter
1450
+ return flatten(flatMapComponents(matched, function (def, _, match, key) {
1451
+ var guard = extractGuard(def, 'beforeRouteEnter')
1372
1452
  if (guard) {
1373
- return function routeEnterGuard (to, from, next) {
1374
- return guard(to, from, function (cb) {
1375
- next(cb)
1376
- if (typeof cb === 'function') {
1377
- cbs.push(function () {
1378
- // #750
1379
- // if a router-view is wrapped with an out-in transition,
1380
- // the instance may not have been registered at this time.
1381
- // we will need to poll for registration until current route
1382
- // is no longer valid.
1383
- poll(cb, match.instances, key, isValid)
1384
- })
1385
- }
1453
+ return Array.isArray(guard)
1454
+ ? guard.map(function (guard) { return wrapEnterGuard(guard, cbs, match, key, isValid); })
1455
+ : wrapEnterGuard(guard, cbs, match, key, isValid)
1456
+ }
1457
+ }))
1458
+ }
1459
+
1460
+ function wrapEnterGuard (
1461
+ guard,
1462
+ cbs,
1463
+ match,
1464
+ key,
1465
+ isValid
1466
+ ) {
1467
+ return function routeEnterGuard (to, from, next) {
1468
+ return guard(to, from, function (cb) {
1469
+ next(cb)
1470
+ if (typeof cb === 'function') {
1471
+ cbs.push(function () {
1472
+ // #750
1473
+ // if a router-view is wrapped with an out-in transition,
1474
+ // the instance may not have been registered at this time.
1475
+ // we will need to poll for registration until current route
1476
+ // is no longer valid.
1477
+ poll(cb, match.instances, key, isValid)
1386
1478
  })
1387
1479
  }
1388
- }
1389
- })
1480
+ })
1481
+ }
1390
1482
  }
1391
1483
 
1392
- function poll (cb, instances, key, isValid) {
1484
+ function poll (
1485
+ cb, // somehow flow cannot infer this is a function
1486
+ instances,
1487
+ key,
1488
+ isValid
1489
+ ) {
1393
1490
  if (instances[key]) {
1394
1491
  cb(instances[key])
1395
1492
  } else if (isValid()) {
@@ -1431,7 +1528,7 @@ function flatMapComponents (
1431
1528
  matched,
1432
1529
  fn
1433
1530
  ) {
1434
- return Array.prototype.concat.apply([], matched.map(function (m) {
1531
+ return flatten(matched.map(function (m) {
1435
1532
  return Object.keys(m.components).map(function (key) { return fn(
1436
1533
  m.components[key],
1437
1534
  m.instances[key],
@@ -1440,19 +1537,25 @@ function flatMapComponents (
1440
1537
  }))
1441
1538
  }
1442
1539
 
1540
+ function flatten (arr) {
1541
+ return Array.prototype.concat.apply([], arr)
1542
+ }
1543
+
1443
1544
  /* */
1444
1545
 
1546
+ var positionStore = Object.create(null)
1547
+
1445
1548
  function saveScrollPosition (key) {
1446
1549
  if (!key) { return }
1447
- window.sessionStorage.setItem(key, JSON.stringify({
1550
+ positionStore[key] = {
1448
1551
  x: window.pageXOffset,
1449
1552
  y: window.pageYOffset
1450
- }))
1553
+ }
1451
1554
  }
1452
1555
 
1453
1556
  function getScrollPosition (key) {
1454
1557
  if (!key) { return }
1455
- return JSON.parse(window.sessionStorage.getItem(key))
1558
+ return positionStore[key]
1456
1559
  }
1457
1560
 
1458
1561
  function getElementPosition (el) {
@@ -1491,8 +1594,6 @@ var HTML5History = (function (History) {
1491
1594
 
1492
1595
  History.call(this, router, base)
1493
1596
 
1494
- this.transitionTo(getLocation(this.base))
1495
-
1496
1597
  var expectScroll = router.options.scrollBehavior
1497
1598
  window.addEventListener('popstate', function (e) {
1498
1599
  _key = e.state && e.state.key
@@ -1539,9 +1640,10 @@ var HTML5History = (function (History) {
1539
1640
  })
1540
1641
  };
1541
1642
 
1542
- HTML5History.prototype.ensureURL = function ensureURL () {
1643
+ HTML5History.prototype.ensureURL = function ensureURL (push) {
1543
1644
  if (getLocation(this.base) !== this.current.fullPath) {
1544
- replaceState(cleanPath(this.base + this.current.fullPath))
1645
+ var current = cleanPath(this.base + this.current.fullPath)
1646
+ push ? pushState(current) : replaceState(current)
1545
1647
  }
1546
1648
  };
1547
1649
 
@@ -1619,8 +1721,6 @@ function replaceState (url) {
1619
1721
 
1620
1722
  var HashHistory = (function (History) {
1621
1723
  function HashHistory (router, base, fallback) {
1622
- var this$1 = this;
1623
-
1624
1724
  History.call(this, router, base)
1625
1725
 
1626
1726
  // check history fallback deeplinking
@@ -1629,11 +1729,6 @@ var HashHistory = (function (History) {
1629
1729
  }
1630
1730
 
1631
1731
  ensureSlash()
1632
- this.transitionTo(getHash(), function () {
1633
- window.addEventListener('hashchange', function () {
1634
- this$1.onHashChange()
1635
- })
1636
- })
1637
1732
  }
1638
1733
 
1639
1734
  if ( History ) HashHistory.__proto__ = History;
@@ -1675,9 +1770,10 @@ var HashHistory = (function (History) {
1675
1770
  window.history.go(n)
1676
1771
  };
1677
1772
 
1678
- HashHistory.prototype.ensureURL = function ensureURL () {
1679
- if (getHash() !== this.current.fullPath) {
1680
- replaceHash(this.current.fullPath)
1773
+ HashHistory.prototype.ensureURL = function ensureURL (push) {
1774
+ var current = this.current.fullPath
1775
+ if (getHash() !== current) {
1776
+ push ? pushHash(current) : replaceHash(current)
1681
1777
  }
1682
1778
  };
1683
1779
 
@@ -1784,6 +1880,20 @@ var VueRouter = function VueRouter (options) {
1784
1880
  mode = 'abstract'
1785
1881
  }
1786
1882
  this.mode = mode
1883
+
1884
+ switch (mode) {
1885
+ case 'history':
1886
+ this.history = new HTML5History(this, options.base)
1887
+ break
1888
+ case 'hash':
1889
+ this.history = new HashHistory(this, options.base, this.fallback)
1890
+ break
1891
+ case 'abstract':
1892
+ this.history = new AbstractHistory(this)
1893
+ break
1894
+ default:
1895
+ assert(false, ("invalid mode: " + mode))
1896
+ }
1787
1897
  };
1788
1898
 
1789
1899
  var prototypeAccessors = { currentRoute: {} };
@@ -1803,25 +1913,19 @@ VueRouter.prototype.init = function init (app /* Vue component instance */) {
1803
1913
 
1804
1914
  this.app = app
1805
1915
 
1806
- var ref = this;
1807
- var mode = ref.mode;
1808
- var options = ref.options;
1809
- var fallback = ref.fallback;
1810
- switch (mode) {
1811
- case 'history':
1812
- this.history = new HTML5History(this, options.base)
1813
- break
1814
- case 'hash':
1815
- this.history = new HashHistory(this, options.base, fallback)
1816
- break
1817
- case 'abstract':
1818
- this.history = new AbstractHistory(this)
1819
- break
1820
- default:
1821
- assert(false, ("invalid mode: " + mode))
1916
+ var history = this.history
1917
+
1918
+ if (history instanceof HTML5History) {
1919
+ history.transitionTo(getLocation(history.base))
1920
+ } else if (history instanceof HashHistory) {
1921
+ history.transitionTo(getHash(), function () {
1922
+ window.addEventListener('hashchange', function () {
1923
+ history.onHashChange()
1924
+ })
1925
+ })
1822
1926
  }
1823
1927
 
1824
- this.history.listen(function (route) {
1928
+ history.listen(function (route) {
1825
1929
  this$1.app._route = route
1826
1930
  })
1827
1931
  };