I'm using VueJS without using Vue CLI. I would like to add a sitemap.xml
to my router but I'm struggling to understand how to use the vue-router-sitemap
library.
I've tried using the code mentioned but it doesn't specify where it should be added.
import VueRouterSitemap from 'vue-router-sitemap';
import path from 'path';
import { router } from 'router';
...
export const sitemapMiddleware = () => {
return (req, res) => {
res.set('Content-Type', 'application/xml');
const staticSitemap = path.resolve('dist/static', 'sitemap.xml');
const filterConfig = {
isValid: false,
rules: [
/\/example-page/,
/\*/,
],
};
new VueRouterSitemap(router).filterPaths(filterConfig).build('http://example.com').save(staticSitemap);
return res.sendFile(staticSitemap);
};
};
app.get('/sitemap.xml', sitemapMiddleware());
If I add this file anywhere then the app
variable doesn't exist (as I would expect). I'm assuming this has to be placed somewhere in particular.
I can't find any other examples of how to do this and other questions about this library have remained unanswered on reddit or stackoverflow.
What is the correct method of adding a sitemap.xml
to a VueJS project?