https://github.com/40818419/vue-router-sitemap
Generate sitemap.xml by vue-router configuration
https://github.com/40818419/vue-router-sitemap
sitemap vue vue-router vue-router-sitemap
Last synced: 4 months ago
JSON representation
Generate sitemap.xml by vue-router configuration
- Host: GitHub
- URL: https://github.com/40818419/vue-router-sitemap
- Owner: 40818419
- Created: 2018-03-26T21:36:44.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T18:35:45.000Z (about 3 years ago)
- Last Synced: 2024-07-05T21:42:09.945Z (over 1 year ago)
- Topics: sitemap, vue, vue-router, vue-router-sitemap
- Language: JavaScript
- Size: 1.09 MB
- Stars: 115
- Watchers: 4
- Forks: 15
- Open Issues: 26
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-vue - vue-router-sitemap - Generate sitemap.xml by vue-router configuration ` 📝 10 months ago` (UI Utilities [🔝](#readme))
- awesome-vue - vue-router-sitemap ★53 - Generate sitemap.xml by vue-router configuration (UI Utilities / Routing)
- awesome-vue - vue-router-sitemap - Generate sitemap.xml by vue-router configuration (UI Utilities / Routing)
- awesome-vue - vue-router-sitemap - Generate sitemap.xml by vue-router configuration (Components & Libraries / UI Utilities)
README
# vue-router-sitemap
Generate sitemap.xml by vue-router configuration
## Install
`npm i --save vue-router-sitemap`
## Example usage
```js
// router.js
import VueRouter from 'vue-router';
export const router: VueRouter = new VueRouter(
{
routes: [
{
path: '/',
name: 'index',
component: Index,
},
],
},
);
```
```js
// 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