Skip to content

Commit

Permalink
Merge pull request AsgardCms#752 from mikemand/hotfix/vue-router-dupl…
Browse files Browse the repository at this point in the history
…icate-navigation

Catch 'NavigationDuplicated' error and ignore it
  • Loading branch information
nWidart authored Feb 5, 2020
2 parents 65f978b + 37dea83 commit bf02285
Show file tree
Hide file tree
Showing 24 changed files with 5,605 additions and 6,258 deletions.
5 changes: 4 additions & 1 deletion Modules/Core/Assets/js/components/EditButtonComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
</template>

<script>
import ShortcutHelper from '../../../../Core/Assets/js/mixins/ShortcutHelper';
export default {
mixins: [ShortcutHelper],
props: {
to: { required: true, type: Object },
},
methods: {
goToEditPage() {
this.$router.push(this.to);
this.pushRoute(this.to);
},
},
};
Expand Down
14 changes: 12 additions & 2 deletions Modules/Core/Assets/js/mixins/ShortcutHelper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
export default {
methods: {
pushRoute(route) {
this.$router.push(route);
pushRoute(route, onError) {
this.$router.push(route, () => {}, (error, ...args) => {
// vue-router 3.1.0+ push/replace causes NavigationDuplicated error
// for routing to the same location
if (error.name === 'NavigationDuplicated') {
return;
}

if (typeof onError === 'function') {
onError(error, ...args);
}
});
},
},
};
8 changes: 5 additions & 3 deletions Modules/Media/Assets/js/components/MediaForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@
import Form from 'form-backend-validation';
import FormErrors from '../../../../Core/Assets/js/components/FormErrors.vue';
import TagsInput from '../../../../Tag/Assets/js/components/TagInput.vue';
import ShortcutHelper from '../../../../Core/Assets/js/mixins/ShortcutHelper';
export default {
components: { FormErrors, TagsInput },
mixins: [ShortcutHelper],
props: {
locales: { default: null, type: Object },
},
Expand Down Expand Up @@ -157,7 +159,7 @@
type: 'success',
message: response.message,
});
this.$router.push({ name: 'admin.media.media.index', query: { folder_id: this.media.folder_id } });
this.pushRoute({ name: 'admin.media.media.index', query: { folder_id: this.media.folder_id } });
})
.catch((error) => {
console.log(error);
Expand All @@ -170,10 +172,10 @@
},
onCancel() {
if (this.media.folder_id === 0) {
this.$router.push({ name: 'admin.media.media.index', query: {} });
this.pushRoute({ name: 'admin.media.media.index', query: {} });
return;
}
this.$router.push({ name: 'admin.media.media.index', query: { folder_id: this.media.folder_id } });
this.pushRoute({ name: 'admin.media.media.index', query: { folder_id: this.media.folder_id } });
},
},
};
Expand Down
10 changes: 6 additions & 4 deletions Modules/Media/Assets/js/components/MediaList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@
import UploadZone from './UploadZone.vue';
import DeleteButton from '../../../../Core/Assets/js/components/DeleteComponent.vue';
import EditButton from '../../../../Core/Assets/js/components/EditButtonComponent.vue';
import ShortcutHelper from '../../../../Core/Assets/js/mixins/ShortcutHelper';
export default {
components: { MoveDialog, NewFolder, RenameFolder, UploadZone, DeleteButton, EditButton },
mixins: [ShortcutHelper],
props: {
singleModal: { default: false, type: Boolean },
eventName: { default: null, type: String },
Expand Down Expand Up @@ -262,7 +264,7 @@
enterFolder(scope) {
this.tableIsLoading = true;
this.folderId = scope.row.id;
this.$router.push({ query: { folder_id: scope.row.id } });
this.pushRoute({ query: { folder_id: scope.row.id } });
},
insertMedia(scope) {
this.$events.emit(this.eventName, scope.row);
Expand All @@ -283,9 +285,9 @@
this.tableIsLoading = true;
this.folderId = folderId;
if (folderId === 0) {
this.$router.push({ query: {} });
this.pushRoute({ query: {} });
} else {
this.$router.push({ query: { folder_id: folderId } });
this.pushRoute({ query: { folder_id: folderId } });
}
},
batchDelete() {
Expand Down Expand Up @@ -317,7 +319,7 @@
});
},
goToEdit(scope) {
this.$router.push({ name: 'admin.media.media.edit', params: { mediaId: scope.row.id } });
this.pushRoute({ name: 'admin.media.media.edit', params: { mediaId: scope.row.id } });
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions Modules/Page/Assets/js/components/PageForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
type: 'success',
message: response.message,
});
this.$router.push({ name: 'admin.page.page.index' });
this.pushRoute({ name: 'admin.page.page.index' });
})
.catch((error) => {
console.log(error);
Expand All @@ -232,7 +232,7 @@
});
},
onCancel() {
this.$router.push({ name: 'admin.page.page.index' });
this.pushRoute({ name: 'admin.page.page.index' });
},
fetchTemplates() {
axios.get(route('api.page.page-templates.index'))
Expand Down
2 changes: 1 addition & 1 deletion Modules/Page/Assets/js/components/PageTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
this.selectedPages = selectedPages;
},
goToEdit(scope) {
this.$router.push({ name: 'admin.page.page.edit', params: { pageId: scope.row.id } });
this.pushRoute({ name: 'admin.page.page.edit', params: { pageId: scope.row.id } });
},
editRoute(scope) {
return route('admin.page.page.edit', [scope.row.id]);
Expand Down
4 changes: 2 additions & 2 deletions Modules/User/Assets/js/components/RoleForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
type: 'success',
message: response.message,
});
this.$router.push({ name: 'admin.user.role.index' });
this.pushRoute({ name: 'admin.user.role.index' });
})
.catch((error) => {
console.log(error);
Expand All @@ -127,7 +127,7 @@
});
},
onCancel() {
this.$router.push({ name: 'admin.user.role.index' });
this.pushRoute({ name: 'admin.user.role.index' });
},
generateSlug() {
this.role.slug = this.slugify(this.role.name);
Expand Down
2 changes: 1 addition & 1 deletion Modules/User/Assets/js/components/RoleTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
this.queryServer({ search: query.target.value });
}, 300),
goToEdit(scope) {
this.$router.push({ name: 'admin.user.role.edit', params: { roleId: scope.row.id } });
this.pushRoute({ name: 'admin.user.role.edit', params: { roleId: scope.row.id } });
},
editRoute(scope) {
return route('admin.user.role.edit', [scope.row.id]);
Expand Down
4 changes: 2 additions & 2 deletions Modules/User/Assets/js/components/UserForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
type: 'success',
message: response.message,
});
this.$router.push({ name: 'admin.user.user.index' });
this.pushRoute({ name: 'admin.user.user.index' });
})
.catch((error) => {
console.log(error);
Expand All @@ -177,7 +177,7 @@
});
},
onCancel() {
this.$router.push({ name: 'admin.user.user.index' });
this.pushRoute({ name: 'admin.user.user.index' });
},
fetchUser() {
this.loading = true;
Expand Down
2 changes: 1 addition & 1 deletion Modules/User/Assets/js/components/UserTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
this.queryServer({ search: query.target.value });
}, 300),
goToEdit(scope) {
this.$router.push({ name: 'admin.user.user.edit', params: { userId: scope.row.id } });
this.pushRoute({ name: 'admin.user.user.edit', params: { userId: scope.row.id } });
},
editRoute(scope) {
return route('admin.user.user.edit', [scope.row.id]);
Expand Down
2 changes: 1 addition & 1 deletion public/css/app.css

Large diffs are not rendered by default.

Loading

0 comments on commit bf02285

Please sign in to comment.