vue-router#useRoute TypeScript Examples
The following examples show how to use
vue-router#useRoute.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: useBreadcrumbTitle.ts From vite-vue3-ts with MIT License | 6 votes |
useBreadcrumbTitle = (isAddOn = true) => {
const route = useRoute();
const title = ref(route.meta.title);
watch(
() => route.meta.title,
(val) => {
title.value = val;
},
);
const changeTitle = (val: string) => (title.value = val);
onMounted(() => isAddOn && emitter.on(key, changeTitle));
onUnmounted(() => isAddOn && emitter.off(key, changeTitle));
const setBreadcrumbTitle = (title: string) => emitter.emit(key, title);
return {
title,
setBreadcrumbTitle,
};
}
Example #2
Source File: index.ts From vite-ssr with MIT License | 6 votes |
export async function useFetchRepos() {
const { initialState } = useContext()
const { name } = useRoute()
let state = initialState[name as string] || null
if (!state) {
state = await (
await fetch('https://api.github.com/orgs/vuejs/repos')
).json()
if (import.meta.env.SSR) {
initialState[name as string] = state
}
}
return state
}
Example #3
Source File: context.ts From theila with Mozilla Public License 2.0 | 6 votes |
export function getContext(route: any = null) {
route = route || useRoute();
const name = contextName();
const res = {};
if(name)
res["name"] = name;
if(route.params && route.params.node)
res["nodes"] = [route.params.node];
if(route.query && route.query.namespace && route.query.cluster && route.query.uid) {
res["cluster"] = {
"name": route.query.cluster,
"namespace": route.query.namespace || "default",
"uid": route.query.uid
};
}
return Context.fromPartial(res);
}