|
1 | 1 | import { createApp } from 'vue' |
2 | | -import type { ParsedContent } from '@nuxt/content/dist/runtime/types' |
| 2 | +import type { ParsedContent } from '@nuxt/content' |
3 | 3 | import type { RouteLocationNormalized } from 'vue-router' |
4 | 4 | import type { AppConfig } from 'nuxt/schema' |
5 | 5 | import ContentPreviewMode from '../components/ContentPreviewMode.vue' |
@@ -180,15 +180,23 @@ export const useStudio = () => { |
180 | 180 | switch (type) { |
181 | 181 | case 'nuxt-studio:editor:file-selected': { |
182 | 182 | const content = await findContentItem(payload.path) |
183 | | - if (!content) { |
| 183 | + if (!content || content._partial) { |
184 | 184 | // Do not navigate to another page if content is not found |
185 | 185 | // This makes sure that user stays on the same page when navigation through directories in the editor |
| 186 | + // Also, We should not navigate if content is a partial |
| 187 | + return |
186 | 188 | } |
187 | | - else if (content._partial || !String(payload.path).endsWith('.md')) { |
188 | | - // Partials and non-markdown files should use as helpers for other content files, like `_dir.yml` |
189 | | - // We should not navigate if content is a partial or non-markdown file |
| 189 | + |
| 190 | + // Ensure that the content is related to a valid route for non markdown files |
| 191 | + if (!String(payload.path).endsWith('.md')) { |
| 192 | + const resolvedRoute = router.resolve(content._path) |
| 193 | + if (!resolvedRoute || !resolvedRoute.matched || resolvedRoute.matched.length === 0) { |
| 194 | + return |
| 195 | + } |
190 | 196 | } |
191 | | - else if (content._path !== useRoute().path) { |
| 197 | + |
| 198 | + // Navigate to the selected content |
| 199 | + if (content._path !== useRoute().path) { |
192 | 200 | editorSelectedPath.value = content._path! |
193 | 201 | router.push(content._path!) |
194 | 202 | } |
@@ -235,6 +243,7 @@ export const useStudio = () => { |
235 | 243 | route.meta.studio_page_contentId = page?._id |
236 | 244 | }) |
237 | 245 |
|
| 246 | + // @ts-expect-error custom hook |
238 | 247 | nuxtApp.hook('nuxt-studio:preview:ready', () => { |
239 | 248 | window.parent.postMessage({ |
240 | 249 | type: 'nuxt-studio:preview:ready', |
|
0 commit comments