d3xter-dev / sitemap-module-nuxt-3

Sitemap Module for Nuxt 3
https://sitemap.nuxtjs.org
MIT License
63 stars 12 forks source link

clear document needed #3

Closed thehatami closed 2 years ago

thehatami commented 2 years ago

hi, please create a simple document for implemented.

d3xter-dev commented 2 years ago

What?

thehatami commented 2 years ago

hi dexter. i try to implement a very simple project in nuxt3 and use your repo for sitemap.

i added below lines in my nuxt.config.ts:

import dynamicRoutes from './helpers/dynamicRoutes'
...
sitemap: {
    hostname: 'https://example.com',
    path: 'sitemap.xml',
    cacheTime: 1,
    routes: dynamicRoutes,
    defaults: {
      changefreq: 'daily',
      priority: 1,
      lastmod: new Date().toISOString(),
    },
  },

create a folder "helper" and add a file "dynamicRoutes.ts" in it with below lines:

 export default async () => {
  return await $fetch('/api/sitemap_routes', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

finally create folder "api" and a file in it "sitemap_routes.ts" with below lines:

import { IncomingMessage, ServerResponse } from 'http'
/**
 * We are using Storyblok as our CMS,
 * in order to have all news and testimonials pages in our sitemap
 * we need to fetch some from Storyblok
 */
export default async (req: IncomingMessage, res: ServerResponse) => {
  if (req.method !== 'POST') {
    res.statusCode = 405
    res.end()
    return
  }
  const config = useRuntimeConfig()
  console.log('[vue-sitemap] generate dynamic routes')

  const fetchRoutes = async (slug) => {
    const routes = []
    const pageInfo = []
    return routes
  }

  return[]
}

but still i get [Vue Router warn]: No match found for location with path "/sitemap.xml"

what is my wrong?

oripka commented 2 years ago

I think you need to put the following in your nuxt.config.ts

 modules: [
    '@funken-studio/sitemap-nuxt-3',
]

The documentation is missing this little detail.

d3xter-dev commented 2 years ago

@oripka Thanks, added.