Skip to content
Generate sitemap.xml by vue-router configuration
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src add .npmignore Nov 11, 2018
types initial commit May 20, 2018
.babelrc
.eslintrc.js initial commit May 20, 2018
.gitignore
.npmignore
README.md
index.js readme Sep 9, 2018
package-lock.json chore(volns): fixed volnurabilities Nov 23, 2018
package.json

README.md

vue-router-sitemap

Generate sitemap.xml by vue-router configuration

Install

npm i --save vue-router-sitemap

Example usage

// router.js

import VueRouter from 'vue-router';

export const router: VueRouter = new VueRouter(
  {
    routes: [
      {
        path:      '/',
        name:      'index',
        component: Index,
      },
    ],
  },
);
// sitemapMiddleware.js

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());
...

License

MIT

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.