Skip to content

Commit

Permalink
router: Don't call middleware and asyncData on query changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Atinux committed Nov 1, 2017
1 parent 2c8023b commit 6e44afe
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/app/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,11 @@ function mapTransitions(Components, to, from) {
}

async function loadAsyncComponents (to, from, next) {
// Check if route hash changed (this._hashChanged)
const fromPath = from.fullPath.split('#')[0]
const toPath = to.fullPath.split('#')[0]
this._hashChanged = fromPath === toPath
// Check if route path changed (this._pathChanged)
this._pathChanged = from.path !== to.path

<% if (loading) { %>
if (!this._hashChanged && this.$loading.start) {
if (this._pathChanged && this.$loading.start) {
this.$loading.start()
}
<% } %>
Expand Down Expand Up @@ -173,7 +171,7 @@ function callMiddleware (Components, context, layout) {
}

async function render (to, from, next) {
if (this._hashChanged) return next()
if (this._pathChanged === false) return next()

// nextCalled is true when redirected
let nextCalled = false
Expand Down Expand Up @@ -258,7 +256,7 @@ async function render (to, from, next) {
await Promise.all(Components.map((Component, i) => {
// Check if only children route changed
Component._path = compile(to.matched[i].path)(to.params)
if (!this._hadError && this._isMounted && Component._path === _lastPaths[i] && (i + 1) !== Components.length) {
if (!this._hadError && this._isMounted && Component._path === _lastPaths[i]) {
return Promise.resolve()
}

Expand Down Expand Up @@ -347,7 +345,7 @@ function showNextPage(to) {
// When navigating on a different route but the same component is used, Vue.js
// Will not update the instance data, so we have to update $data ourselves
function fixPrepatch (to, from) {
if (this._hashChanged) return
if (this._pathChanged === false) return

Vue.nextTick(() => {
const instances = getChangedComponentsInstances(to, from)
Expand Down

0 comments on commit 6e44afe

Please sign in to comment.