New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-router-sitemap-maker

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-router-sitemap-maker

Generates a sitemap from react-router-dom routes

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
41
decreased by-16.33%
Maintainers
1
Weekly downloads
 
Created
Source

react-router-sitemap-maker

Testing

Generates a sitemap from react-router-dom routes.

Available on NPM: NPM

Usage

Routes layout

The sitemap generator expects a Routes element containing one or multiple Route elements in it. Like the following example:

// src/routes.jsx
import { Routes, Route } from "react-router-dom";

const MyRoutes = () => {
	return (
		<Routes>
			<Route path="/" element={<AnyElement />}></Route>
			<Route index element={<AnyElement />} />
			<Route path="Contact" element={<AnyElement />} />
			<Route path="*" element={<AnyElement />} />
		</Routes>
	);
};

Note: The Routes cannot be wrapped in a HashRouter or a BrowserRouter, because this requires the DOM, thus the code cannot be ran server side.

Creating the builder file

To create the sitemap you need a builder file.

You can possibly run this after you ran the actual build and put the sitemap in the dist or the build folder.

Alternatively you could run it before the building process and put it in the public folder.

// builders/sitemap.js

import GenerateSitemap from "react-router-sitemap-maker";
import Routes from "../src/routes";

const sitemapData = await GenerateSitemap(Routes(), {
	baseUrl: "https://rikthepixel.github.io",
	hashrouting: true,
	changeFrequency: "monthly"
});

sitemapData.toFile("./dist/sitemap.xml");

Run the builder

These are some possible ways to run the sitemap builder file.

Using babel-node:

(Additional setup may be required to get babel-node to run JSX)

babel-node ./builders/sitemap.js
Using vite-node:

(vite-node should run JSX out of the box)

vite-node ./builders/sitemap.js

Keywords

FAQs

Package last updated on 26 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc