Skip to content

Commit

Permalink
Fix(router): add catch for router push and replace, fixes #150
Browse files Browse the repository at this point in the history
  • Loading branch information
Armour committed Nov 8, 2020
1 parent b0b3e31 commit 60320ad
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
node_modules
/dist

/tests/e2e/videos/
/tests/e2e/screenshots/
/tests/**/coverage/

# local env files
Expand Down
1 change: 0 additions & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ Javascript 版本:
├── .env.xxx # 环境变量配置
├── .eslintrc.js # eslint 配置
├── babel.config.js # babel-loader 配置
├── cypress.json # e2e 测试配置
├── jest.config.js # jest 单元测试配置
├── package.json # package.json 依赖
├── postcss.config.js # postcss 配置
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ Understanding and learning these knowledge in advance will greatly help you on u
├── .env.xxx # env variable configuration
├── .eslintrc.js # eslint config
├── babel.config.js # babel config
├── cypress.json # e2e test config
├── jest.config.js # jest unit test config
├── package.json # package.json
├── postcss.config.js # postcss config
Expand Down
4 changes: 0 additions & 4 deletions src/components/Breadcrumb/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,11 @@ export default class extends Vue {
const { redirect, path } = item
if (redirect) {
this.$router.push(redirect).catch(err => {
// Throw Error "NavigationDuplicated"
// https://github.com/vuejs/vue-router/issues/2872#issuecomment-522341874
console.warn(err)
})
return
}
this.$router.push(this.pathCompile(path)).catch(err => {
// Throw Error "NavigationDuplicated"
// https://github.com/vuejs/vue-router/issues/2872#issuecomment-522341874
console.warn(err)
})
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/HeaderSearch/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export default class extends Vue {
}
private change(route: RouteConfig) {
this.$router.push(route.path)
this.$router.push(route.path).catch(err => {
console.warn(err)
})
this.search = ''
this.options = []
this.$nextTick(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/SizeSelect/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export default class extends Vue {
this.$nextTick(() => {
this.$router.replace({
path: '/redirect' + fullPath
}).catch(err => {
console.warn(err)
})
})
}
Expand Down
4 changes: 3 additions & 1 deletion src/layout/components/Navbar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ export default class extends Vue {
private async logout() {
await UserModule.LogOut()
this.$router.push(`/login?redirect=${this.$route.fullPath}`)
this.$router.push(`/login?redirect=${this.$route.fullPath}`).catch(err => {
console.warn(err)
})
}
}
</script>
Expand Down
18 changes: 14 additions & 4 deletions src/layout/components/TagsView/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ export default class extends Vue {
this.$nextTick(() => {
this.$router.replace({
path: '/redirect' + fullPath
}).catch(err => {
console.warn(err)
})
})
}
Expand All @@ -184,7 +186,9 @@ export default class extends Vue {
private closeOthersTags() {
if (this.selectedTag.fullPath !== this.$route.path && this.selectedTag.fullPath !== undefined) {
this.$router.push(this.selectedTag.fullPath)
this.$router.push(this.selectedTag.fullPath).catch(err => {
console.warn(err)
})
}
TagsViewModule.delOthersViews(this.selectedTag)
this.moveToCurrentTag()
Expand All @@ -201,14 +205,20 @@ export default class extends Vue {
private toLastView(visitedViews: ITagView[], view: ITagView) {
const latestView = visitedViews.slice(-1)[0]
if (latestView !== undefined && latestView.fullPath !== undefined) {
this.$router.push(latestView.fullPath)
this.$router.push(latestView.fullPath).catch(err => {
console.warn(err)
})
} else {
// Default redirect to the home page if there is no tags-view, adjust it if you want
if (view.name === 'Dashboard') {
// to reload home page
this.$router.replace({ path: '/redirect' + view.fullPath })
this.$router.replace({ path: '/redirect' + view.fullPath }).catch(err => {
console.warn(err)
})
} else {
this.$router.push('/')
this.$router.push('/').catch(err => {
console.warn(err)
})
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/views/error-page/401.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export default class extends Vue {
private back() {
if (this.$route.query.noGoBack) {
this.$router.push({ path: '/dashboard' })
this.$router.push({ path: '/dashboard' }).catch(err => {
console.warn(err)
})
} else {
this.$router.go(-1)
}
Expand Down
2 changes: 2 additions & 0 deletions src/views/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ export default class extends Vue {
this.$router.push({
path: this.redirect || '/',
query: this.otherQuery
}).catch(err => {
console.warn(err)
})
// Just to simulate the time of the request
setTimeout(() => {
Expand Down
4 changes: 3 additions & 1 deletion src/views/permission/page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import SwitchRoles from './components/SwitchRoles.vue'
})
export default class extends Vue {
private handleRolesChange() {
this.$router.push({ path: '/permission/index?' + +new Date() })
this.$router.push({ path: '/permission/index?' + +new Date() }).catch(err => {
console.warn(err)
})
}
}
</script>
4 changes: 3 additions & 1 deletion src/views/redirect/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export default class extends Vue {
created() {
const { params, query } = this.$route
const { path } = params
this.$router.replace({ path: '/' + path, query })
this.$router.replace({ path: '/' + path, query }).catch(err => {
console.warn(err)
})
}
render() {
Expand Down
4 changes: 3 additions & 1 deletion src/views/tab/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export default class extends Vue {
@Watch('activeName')
private onActiveNameChange(value: string) {
this.$router.push(`${this.$route.path}?tab=${value}`)
this.$router.push(`${this.$route.path}?tab=${value}`).catch(err => {
console.warn(err)
})
}
created() {
Expand Down

0 comments on commit 60320ad

Please sign in to comment.