|
1 | 1 | /**
|
2 |
| - * vue-router v2.0.0-rc.1 |
| 2 | + * vue-router v2.0.0-rc.2 |
3 | 3 | * (c) 2016 Evan You
|
4 | 4 | * @license MIT
|
5 | 5 | */
|
|
1061 | 1061 | redirectedFrom
|
1062 | 1062 | ) {
|
1063 | 1063 | var route = {
|
1064 |
| - name: location.name, |
| 1064 | + name: location.name || (record && record.name), |
1065 | 1065 | path: location.path || '/',
|
1066 | 1066 | hash: location.hash || '',
|
1067 | 1067 | query: location.query || {},
|
|
1179 | 1179 | }
|
1180 | 1180 |
|
1181 | 1181 | var History = function History (router , base ) {
|
1182 |
| - var this$1 = this; |
1183 |
| - |
1184 | 1182 | this.router = router
|
1185 | 1183 | this.base = normalizeBase(base)
|
1186 | 1184 | // start with a route object that stands for "nowhere"
|
1187 | 1185 | this.current = createRoute(null, {
|
1188 | 1186 | path: '__vue_router_init__'
|
1189 | 1187 | })
|
1190 | 1188 | this.pending = null
|
1191 |
| - this.transitionTo(this.getLocation(), function (route) { |
1192 |
| - this$1.onInit(route) |
1193 |
| - }) |
1194 | 1189 | };
|
1195 | 1190 |
|
1196 | 1191 | History.prototype.listen = function listen (cb ) {
|
|
1378 | 1373 |
|
1379 | 1374 | History.call(this, router, base)
|
1380 | 1375 |
|
| 1376 | + var initialLocation = getLocation(this.base) |
| 1377 | + this.transitionTo(initialLocation, function (route) { |
| 1378 | + // possible redirect on start |
| 1379 | + var url = cleanPath(this$1.base + this$1.current.fullPath) |
| 1380 | + if (initialLocation !== url) { |
| 1381 | + replaceState(url) |
| 1382 | + } |
| 1383 | + }) |
| 1384 | + |
1381 | 1385 | var expectScroll = router.options.scrollBehavior
|
1382 | 1386 | window.addEventListener('popstate', function (e) {
|
1383 | 1387 | _key = e.state && e.state.key
|
1384 | 1388 | var current = this$1.current
|
1385 |
| - this$1.transitionTo(this$1.getLocation(), function (next) { |
| 1389 | + this$1.transitionTo(getLocation(this$1.base), function (next) { |
1386 | 1390 | if (expectScroll) {
|
1387 | 1391 | this$1.handleScroll(next, current, true)
|
1388 | 1392 | }
|
|
1400 | 1404 | HTML5History.prototype = Object.create( History && History.prototype );
|
1401 | 1405 | HTML5History.prototype.constructor = HTML5History;
|
1402 | 1406 |
|
1403 |
| - HTML5History.prototype.onInit = function onInit () { |
1404 |
| - // possible redirect on start |
1405 |
| - var url = cleanPath(this.base + this.current.fullPath) |
1406 |
| - if (this.getLocation() !== url) { |
1407 |
| - replaceState(url) |
1408 |
| - } |
1409 |
| - }; |
1410 |
| - |
1411 | 1407 | HTML5History.prototype.go = function go (n ) {
|
1412 | 1408 | window.history.go(n)
|
1413 | 1409 | };
|
|
1432 | 1428 | })
|
1433 | 1429 | };
|
1434 | 1430 |
|
1435 |
| - HTML5History.prototype.getLocation = function getLocation$1 () { |
1436 |
| - return getLocation(this.base) |
1437 |
| - }; |
1438 |
| - |
1439 | 1431 | HTML5History.prototype.handleScroll = function handleScroll (to , from , isPop ) {
|
1440 | 1432 | var router = this.router
|
1441 | 1433 | if (!router.app) {
|
|
1510 | 1502 | var this$1 = this;
|
1511 | 1503 |
|
1512 | 1504 | History.call(this, router, base)
|
| 1505 | + |
1513 | 1506 | // check history fallback deeplinking
|
1514 | 1507 | if (fallback && this.checkFallback()) {
|
1515 | 1508 | return
|
1516 | 1509 | }
|
| 1510 | + |
1517 | 1511 | ensureSlash()
|
| 1512 | + this.transitionTo(getHash(), function (route) { |
| 1513 | + // possible redirect on start |
| 1514 | + if (getHash() !== route.fullPath) { |
| 1515 | + replaceHash(route.fullPath) |
| 1516 | + } |
| 1517 | + }) |
| 1518 | + |
1518 | 1519 | window.addEventListener('hashchange', function () {
|
1519 | 1520 | this$1.onHashChange()
|
1520 | 1521 | })
|
|
1524 | 1525 | HashHistory.prototype = Object.create( History && History.prototype );
|
1525 | 1526 | HashHistory.prototype.constructor = HashHistory;
|
1526 | 1527 |
|
1527 |
| - HashHistory.prototype.onInit = function onInit () { |
1528 |
| - // possible redirect on start |
1529 |
| - if (getHash() !== this.current.fullPath) { |
1530 |
| - replaceHash(this.current.fullPath) |
1531 |
| - } |
1532 |
| - }; |
1533 |
| - |
1534 | 1528 | HashHistory.prototype.checkFallback = function checkFallback () {
|
1535 | 1529 | var location = getLocation(this.base)
|
1536 | 1530 | if (!/^\/#/.test(location)) {
|
|
1545 | 1539 | if (!ensureSlash()) {
|
1546 | 1540 | return
|
1547 | 1541 | }
|
1548 |
| - this.transitionTo(this.getLocation(), function (route) { |
| 1542 | + this.transitionTo(getHash(), function (route) { |
1549 | 1543 | replaceHash(route.fullPath)
|
1550 | 1544 | })
|
1551 | 1545 | };
|
|
1566 | 1560 | window.history.go(n)
|
1567 | 1561 | };
|
1568 | 1562 |
|
1569 |
| - HashHistory.prototype.getLocation = function getLocation$1 () { |
1570 |
| - return getHash() |
1571 |
| - }; |
1572 |
| - |
1573 | 1563 | return HashHistory;
|
1574 | 1564 | }(History));
|
1575 | 1565 |
|
|
1612 | 1602 | AbstractHistory.prototype = Object.create( History && History.prototype );
|
1613 | 1603 | AbstractHistory.prototype.constructor = AbstractHistory;
|
1614 | 1604 |
|
1615 |
| - AbstractHistory.prototype.onInit = function onInit () { |
1616 |
| - this.stack = [this.current] |
1617 |
| - }; |
1618 |
| - |
1619 | 1605 | AbstractHistory.prototype.push = function push (location ) {
|
1620 | 1606 | var this$1 = this;
|
1621 | 1607 |
|
|
1648 | 1634 | })
|
1649 | 1635 | };
|
1650 | 1636 |
|
1651 |
| - AbstractHistory.prototype.setInitialRoute = function setInitialRoute (route ) { |
1652 |
| - this.current = route |
1653 |
| - this.stack = [this.current] |
1654 |
| - this.index = 0 |
1655 |
| - }; |
1656 |
| - |
1657 |
| - AbstractHistory.prototype.getLocation = function getLocation () { |
1658 |
| - return '/' |
1659 |
| - }; |
1660 |
| - |
1661 | 1637 | return AbstractHistory;
|
1662 | 1638 | }(History));
|
1663 | 1639 |
|
|
1681 | 1657 | this.mode = mode
|
1682 | 1658 | };
|
1683 | 1659 |
|
| 1660 | + var prototypeAccessors = { currentRoute: {} }; |
| 1661 | + |
| 1662 | + prototypeAccessors.currentRoute.get = function () { |
| 1663 | + return this.history && this.history.current |
| 1664 | + }; |
| 1665 | + |
1684 | 1666 | VueRouter.prototype.init = function init (app /* Vue component instance */) {
|
1685 | 1667 | var this$1 = this;
|
1686 | 1668 |
|
|
1742 | 1724 | this.go(1)
|
1743 | 1725 | };
|
1744 | 1726 |
|
1745 |
| - VueRouter.prototype.setInitialLocation = function setInitialLocation (location ) { |
1746 |
| - var route = this.match(location) |
1747 |
| - if (this.history instanceof AbstractHistory) { |
1748 |
| - this.history.setInitialRoute(route) |
1749 |
| - } |
1750 |
| - if (this.app) { |
1751 |
| - this.app._route = route |
| 1727 | + VueRouter.prototype.getMatchedComponents = function getMatchedComponents () { |
| 1728 | + if (!this.currentRoute) { |
| 1729 | + return [] |
1752 | 1730 | }
|
| 1731 | + return [].concat.apply([], this.currentRoute.matched.map(function (m) { |
| 1732 | + return Object.keys(m.components).map(function (key) { |
| 1733 | + return m.components[key] |
| 1734 | + }) |
| 1735 | + })) |
1753 | 1736 | };
|
1754 | 1737 |
|
| 1738 | + Object.defineProperties( VueRouter.prototype, prototypeAccessors ); |
| 1739 | + |
1755 | 1740 | VueRouter.install = install
|
1756 | 1741 |
|
1757 | 1742 | if (inBrowser && window.Vue) {
|
|
0 commit comments