>,
+ default: ''
+ },
+ /**
+ * 在使用 to 进行路由跳转时,启用 replace 将不会向 history 添加新记录
+ */
+ replace: {
+ type: Boolean,
+ default: false
}
} as const
diff --git a/devui/breadcrumb/src/breadcrumb-item.scss b/devui/breadcrumb/src/breadcrumb-item.scss
index dd06a51aa8420085696847f4577bba91ee02c269..5c3a604685145422edde0ea44ec1e0bee8dc9d51 100644
--- a/devui/breadcrumb/src/breadcrumb-item.scss
+++ b/devui/breadcrumb/src/breadcrumb-item.scss
@@ -30,6 +30,15 @@
color $devui-animation-duration-slow
$devui-animation-ease-in-out-smooth;
}
+
+ .is-link {
+ cursor: pointer;
+
+ &:hover {
+ color: $devui-text;
+ text-decoration: none;
+ }
+ }
}
.devui-breadcrumb-separator {
diff --git a/devui/breadcrumb/src/breadcrumb-item.tsx b/devui/breadcrumb/src/breadcrumb-item.tsx
index 39a2674a21fba7658b348db97c8b824b8a99eede..f8f1ff686f9fa5f973ad8512de8f311ea15aaa72 100644
--- a/devui/breadcrumb/src/breadcrumb-item.tsx
+++ b/devui/breadcrumb/src/breadcrumb-item.tsx
@@ -1,4 +1,11 @@
-import { defineComponent, inject } from 'vue'
+import {
+ defineComponent,
+ inject,
+ onMounted,
+ onBeforeUnmount,
+ ref,
+ getCurrentInstance
+} from 'vue'
import {
breadcrumbItemProps,
@@ -11,13 +18,31 @@ export default defineComponent({
props: breadcrumbItemProps,
setup(props: BreadcrumbItemProps, { slots }) {
const separatorIcon = inject('separatorIcon')
+ const linkClass = props.to ? 'is-link' : ''
+ const link = ref(null)
+ const instance = getCurrentInstance()
+ const router = instance.appContext.config.globalProperties.$router
+ const handleClickLink = () => {
+ if (!props.to || !router) return
+ props.replace ? router.replace(props.to) : router.push(props.to)
+ }
+ onMounted(() => {
+ link.value.addEventListener('click', handleClickLink)
+ })
+
+ onBeforeUnmount(() => {
+ link.value.removeEventListener('click', handleClickLink)
+ })
+
return () => {
const renderBreadcrumbSperator = () => {
return {separatorIcon}
}
return (
- {slots?.default()}
+
+ {slots?.default()}
+
{renderBreadcrumbSperator()}
)
diff --git a/devui/breadcrumb/src/breadcrumb-types.ts b/devui/breadcrumb/src/breadcrumb-types.ts
index f8d43be8c3b06343c891aaa22d5d33cac4cd8998..caebf81bf3e903663ea1946f586e2925af6e3859 100644
--- a/devui/breadcrumb/src/breadcrumb-types.ts
+++ b/devui/breadcrumb/src/breadcrumb-types.ts
@@ -5,6 +5,8 @@ export interface SourceConfig {
link?: string // 跳转的路径
target?: string // 规定在何处打开链接文档
noNavigation?: boolean // 链接是否不可跳转,一般用于当前所处位置不可跳转的配置
+ linkType?: 'hrefLink' | 'routerLink' // 链接类型,默认为'hrefLink'方式,可选'hrefLink' 或 'routerLink'
+ replace: boolean // 在使用 to 进行路由跳转时,启用 replace 将不会向 history 添加新记录
}
export const breadcrumbProps = {
diff --git a/devui/breadcrumb/src/breadcrumb.tsx b/devui/breadcrumb/src/breadcrumb.tsx
index 0da81a2945e7805bb4276a664fe65abf5d6f3a9f..6b5ffeb24d2c3eef01f5af35e43ff5e71bfbaf28 100644
--- a/devui/breadcrumb/src/breadcrumb.tsx
+++ b/devui/breadcrumb/src/breadcrumb.tsx
@@ -18,15 +18,28 @@ export default defineComponent({
const separatorIcon = getPropsSlot(slots, props, 'separatorIcon') ?? '/'
provide('separatorIcon', separatorIcon)
+ const renderBreadcrumbItemRouted = (item) => {
+ return (
+
+ {item.title}
+
+ )
+ }
const renderBreadItemList = (source: SourceConfig[]) => {
return source.map((item: SourceConfig) => {
+ if (!item.noNavigation && item.linkType === 'routerLink') {
+ return renderBreadcrumbItemRouted(item)
+ }
return (
- {!item.noNavigation ? (
+ {/* hrefLink */}
+ {!item.noNavigation &&
+ (!item.linkType || item.linkType === 'hrefLink') ? (
{item.title}
) : null}
+ {/* normal */}
{item.noNavigation ? {item.title} : null}
)
diff --git a/docs/components/breadcrumb/index.md b/docs/components/breadcrumb/index.md
index 2289ae81233295cb21ba0883e0bcec576b49aa5c..243c160b98357b89d99788830ec172e90f96cdc4 100644
--- a/docs/components/breadcrumb/index.md
+++ b/docs/components/breadcrumb/index.md
@@ -14,6 +14,7 @@
```vue
+ Homepage
DevUI
@@ -39,7 +40,7 @@ export default defineComponent({
name: "DBreadcrumbDemoSourceConfig",
setup() {
const source = reactive([
- { title: 'DevUI', link: '/' },
+ { title: 'DevUI', link: '/', linkType: 'routerLink', replace: true },
{ title: 'Breadcrumb', link: 'components/breadcrumb/', noNavigation: true }
])
return {
@@ -52,42 +53,6 @@ export default defineComponent({
:::
### 可下拉的面包屑【TODO】
-
-
-
### 自定义分隔符的面包屑
:::demo
@@ -123,34 +88,20 @@ export default defineComponent({
### d-breadcrumb 参数
-| 参数 | 类型 | 默认 | 说明 | 跳转 Demo |
-| :-----------: | :------------------------------------: | :---------------------------: | :------------------------------------------------- | ------------------------- |
-| separatorIcon | [`string`](#自定义分隔符的面包屑) | '/' | 可选,自定义分隔符样式 | [自定义分隔符的面包屑](#自定义分隔符的面包屑)
-| source | [`Array`](#SourceConfig) | [] | 可选,面包屑根据配置的 source 按照默认渲染方式显示 | [传入source](#传入source) |
+| 参数 | 类型 | 默认 | 说明 | 跳转 Demo |
+| :-----------: | :------------------------------------: | :--: | :------------------------------------------------- | --------------------------------------------- |
+| separatorIcon | [`string`](#自定义分隔符的面包屑) | '/' | 可选,自定义分隔符样式 | [自定义分隔符的面包屑](#自定义分隔符的面包屑) |
+| source | [`Array`](#SourceConfig) | [] | 可选,面包屑根据配置的 source 按照默认渲染方式显示 | [传入source](#传入source) |
-
### 接口 & 类型定义
-
-
### SourceConfig
```ts
@@ -159,5 +110,7 @@ export interface SourceConfig {
link?: string; // 跳转的路径
target?: string // 规定在何处打开链接文档
noNavigation?: boolean; // 链接是否不可跳转,一般用于当前所处位置不可跳转的配置
+ linkType?: 'hrefLink' | 'routerLink'; // 链接类型,默认为'hrefLink'方式,可选'hrefLink' 或 'routerLink'
+ replace: Boolean // 在使用 to 进行路由跳转时,启用 replace 将不会向 history 添加新记录
}
```
\ No newline at end of file