-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to build breadcrumb? #299
Comments
@hongquan do your breadcrumbs use <template v-for="match in route.matches" :key="match.id">
<router-link :to="resolve => resolve(match.name as typeof route['name'])">{{ match.name }}</router-link>
</template> Note if a match has an undefined name, it's not a navigable route. We will see if we can find a better solution for you |
@stackoverfloweth I don't believe I can use
So I only hope to get the full path and the route name to use with <a :href='fullPath'>{{ getTitle(name) }}</a> More context: |
@hongquan you can indeed use <template>
<template v-for="match in matches" :key="match.id">
<router-link :to="match">{{ match }}</router-link>
</template>
<router-view />
</template> import { Url, isUrl, useRoute, useRouter } from '@kitbag/router';
import { computed } from 'vue';
const router = useRouter()
const route = useRoute()
function isRouteName(name: string | undefined): name is typeof route['name'] {
return !!name && name !== 'NotFound'
}
const matches = computed(() => {
return route.matches.reduce<Url[]>((matches, match) => {
if(isRouteName(match.name)){
const url = router.resolve(match.name, route.params)
if(isUrl(url)){
matches.push(url)
}
}
return matches
}, [])
}) Note, the check for |
@stackoverfloweth Thank you. Will try again some day. I canceled the "vue-router to kitbag router migration" attempt due to this issue and another "recursive type resolve" when building navigation bar (which I didn't have time to report). |
@hongquan Thanks for contributing to this project by using it and submitting issues! Sorry to hear your migration didn't succeed. We're going to keep working on making this specific use case (breadcrumbs) a good devx. I'm also very curious about the recursive types issue you had in your nav bar. If you have time to share that one I'd appreciate it. |
I'm going to reopen this as an action item for us to finish improvements to types to make this easier and then either A. Provide a concise snippet, possibly in docs for how to build such a component |
@pleek91 Unfortunately, I cannot reproduce the "recursive type resolve" issue with the "router-preview" example. The summary is that: I want to pass a name and params to import type { RegisteredRoutesName } from '@kitbag/router'
import type { RouterResolve } from '@/routes'
interface Props {
routerName: RegisteredRoutesName
roomId: number
}
function getUrl(resolve: RouterResolve) {
return resolve(props.name, { roomId: props.roomId })
} The export type RouterResolve = typeof router.resolve It seems that, the import of |
I am trying to build a breadcrumb for deep nested pages, to let user easily go to ancestor pages.
In
vue-router
, I useroute.matched
to get the URLs of the ancestor pages. But in@kitbag/router
, there is no way. In@kitbag/router
, theroute.matches
just return the data used for defining routes (inroutes.ts
), wherename
is ofstring | undefined
type, andpath
is just a portion, not a full path.The text was updated successfully, but these errors were encountered: