Skip to content

Commit

Permalink
feat: 面包屑支持路径参数
Browse files Browse the repository at this point in the history
  • Loading branch information
xinufo committed Sep 21, 2019
1 parent 4ca1f3e commit f86cdcb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
13 changes: 9 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"md5": "^2.2.1",
"moment": "^2.24.0",
"nprogress": "^0.2.0",
"path-to-regexp": "^3.1.0",
"viser-vue": "^2.4.6",
"vue": "^2.6.10",
"vue-cropper": "^0.4.9",
Expand Down
9 changes: 8 additions & 1 deletion src/components/tools/Breadcrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
<a-breadcrumb-item v-for="(item, index) in breadList" :key="item.name">
<router-link
v-if="item.name != name && index != 1"
:to="{ path: item.path === '' ? '/' : item.path }"
:to="{ path: item.path === '' ? '/' : pathCompile(item.path) }"
>{{ item.meta.title }}</router-link>
<span v-else>{{ item.meta.title }}</span>
</a-breadcrumb-item>
</a-breadcrumb>
</template>

<script>
import pathToRegexp from 'path-to-regexp'
export default {
data () {
return {
Expand All @@ -31,6 +33,11 @@ export default {
// item.name !== 'index' && this.breadList.push(item)
this.breadList.push(item)
})
},
pathCompile (path) {
const { params } = this.$route
let toPath = pathToRegexp.compile(path)
return toPath(params)
}
},
watch: {
Expand Down

0 comments on commit f86cdcb

Please sign in to comment.