Skip to content

Commit

Permalink
Add proper use of vue router and fix some small vue conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelreichor committed Nov 9, 2024
1 parent b36a6ed commit e0716fd
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 20 deletions.
4 changes: 4 additions & 0 deletions playground/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

<template>
<main>
<nav>
<RouterLink to="/">Go to Home</RouterLink>
<RouterLink to="/news-article-1">Go to News Article 1</RouterLink>
</nav>
<Suspense>
<RouterView />
</Suspense>
Expand Down
28 changes: 19 additions & 9 deletions playground/src/CraftRouter.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<script setup lang="ts">
import { useCraftUrlBuilder, type Config } from '@vue-craftcms';
import Home from './pages/home.vue';
import News from './pages/news.vue';
import { ref } from 'vue';
import { CraftNotImplemented } from '@vue-craftcms';
import { ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { useCraftUrlBuilder, CraftNotImplemented, type Config } from '@vue-craftcms';
import { fetchData } from './utils/fetcher';
import Home from './views/home.vue';
import News from './views/news.vue';
import Headline from './components/headline.vue';
import { fetchData } from './helpers/utils';
const mapping: Config = {
pages: {
Expand All @@ -18,9 +19,18 @@
},
};
const uri = '__home__';
const queryPageUrl = useCraftUrlBuilder('entries').uri(uri).buildUrl('one');
const data = ref(await fetchData(queryPageUrl));
const route = useRoute();
const urlBuilder = useCraftUrlBuilder('entries');
const uri = ref(route.params.pathMatch || '__home__');
const data = ref(await fetchData(urlBuilder.uri(uri.value).buildUrl('one')));
watch(
() => route.fullPath,
async () => {
uri.value = route.params.pathMatch || '__home__';
data.value = await fetchData(urlBuilder.uri(uri.value).buildUrl('one'));
},
);
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion playground/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CraftCms } from '@vue-craftcms';
import router from './router';
import { router } from './router';
import { createApp } from 'vue';
import App from './App.vue';

Expand Down
13 changes: 4 additions & 9 deletions playground/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { createMemoryHistory, createRouter } from 'vue-router';

import { createRouter, createWebHistory } from 'vue-router';
import CraftRouter from './CraftRouter.vue';

const routes = [{ path: '/:pathMatch(.*)*', name: 'CraftRouter', component: CraftRouter }];

const router = createRouter({
history: createMemoryHistory(),
routes,
export const router = createRouter({
history: createWebHistory(),
routes: [{ path: '/:pathMatch(.*)*', component: CraftRouter }],
});

export default router;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { useCraftUrlBuilder } from '@vue-craftcms';
import { fetchData } from '../helpers/utils';
import { fetchData } from '../utils/fetcher';
import { ref } from 'vue';
const props = defineProps({
Expand Down
File renamed without changes.

0 comments on commit e0716fd

Please sign in to comment.