Generate a sitemap using the React Router configuration.
Examples
import Sitemap from 'react-router-sitemap';
const sitemap = (
new Sitemap(<Route path='/home'>)
.build('http://my-site.ru')
.save("./sitemap.xml");
);
Convert a React Router config to an array of paths.
Parameters
router
Route React Router configuration.
Examples
import Sitemap from 'react-router-sitemap';
const sitemap = new Sitemap(<Route path='/home'>);
Filter paths using the specified rules.
Parameters
filterConfig
Object Filter configuration
Properties
rules
Array<RegExp> List filter rules.isValid
Boolean Flag that defines a way to filter paths. Iftrue
, the path satisfying the rules will be included. Iffalse
, the path satisfying the rules will be excluded.
Examples
Config for exclude /auth
and /thanks
{ isValid: false, rules: [/\/auth/, /\/thanks/] }
Config for include /auth
and /thanks
{ isValid: true, rules: [/\/auth/, /\/thanks/] }
Replace the dynamic parameters in paths using the given values.
Parameters
Examples
Config for replacing params :param
in the path /path/:param
{
'/path/:param': [
{ param: 'value' }
]
}
Config for replacing params :param
and :subparam
in the path /path/:param/:subparam
{
'/path/:param/:subparam': [
{ param: 'value', subparam: ['subvalue1', 'subvalue2'] }
]
}
Convert array of paths to sitemap.
Parameters
hostname
String The root name of your site.$1
Object (optional, default{}
)$1.limitCountPaths
(optional, default49999
)$1.lastMod
Date or string that can be evaluated as a date (optional) adds<lastmod>
tag to all of the paths set to the date value passed
Save sitemaps and sitemap index in files.
Parameters
dist
String The path and file name where the sitemap index is saved.publicPath
[String](default '/') optional public path relative to hostname, default: '/'
Module for splitting paths array in multiple arrays for support of large projects
Parameters
paths
[Array] Initial paths array (flattened) (optional, default[]
)size
[Number] (optional, default49999
)
Examples
import { pathsSplitter } from 'react-router-sitemap';
const splitted = pathsSplitter(paths, 49999); // 49999 because of Google sitemap limits
Module for applying params in dynamic paths.
Parameters
paths
[Array<String>] Array of pathsparamsConfig
[Object<String, Array>] Configuration matching parameters and values
Examples
import { paramsApplier as applyParams } from 'react-router-sitemap';
const paths = ['/path/:param'];
const config = {
'/path:param': [
{ param: 'a' },
{ param: [ 'b', 'c' ] },
],
};
const paths = applyParams(paths, config);
// ['/path/a', '/path/b', '/path/c']
import { paramsApplier as applyParams } from 'react-router-sitemap';
const paths = ['/path/:param/:subparam'];
const config = {
'/path/:param/:subparam': [
{ param: 'a', subparam: '1' },
{ param: 'b', subparam: ['2', '3'] },
],
};
const paths = applyParams(paths, config);
// ['/path/a/1', '/path/b/2', '/path/b/3']
Returns Array<String> Array of paths
Module for filtering an array of paths.
Parameters
paths
[Array<String>] Array of pathsrules
[Array<RegExp>] Filter rulesisValidRules
[Boolean] Flag that defines a way to filter paths. Iftrue
, the path satisfying the rules will be included. Iffalse
, the path satisfying the rules will be excluded.
Examples
import { pathsFilter as filterPaths } from 'react-router-sitemap';
const paths = ['/', '/home', '/auth'];
const rules = [/\/auth/];
const isValidRules = false;
const paths = filterPaths(paths, rules, isValidRules);
// ['/', '/home']
import { pathsFilter as filterPaths } from 'react-router-sitemap';
const paths = ['/', '/home', '/auth'];
const rules = [/\/auth/];
const isValidRules = true;
const paths = filterPaths(paths, rules, isValidRules);
// ['/auth']
Returns Array<String> Array of paths.
Creates and returns an array of routes from the given object which may be a JSX route, a plain object route, or an array of either.
Parameters
routes
Route React Router configuration.
Examples
import { routesCreater as createRoutes } from 'react-router-sitemap';
import { routesParser as parseRoutes } from 'react-router-sitemap';
const routes = createRoutes(<Route path='/home'>);
const paths = parseRoutes(routes); // ['/home']
Module for parsing the result of the createRoutes(<Route>)
function.
Parameters
routes
[(Array | Object)] Result of execute functioncreateRoutes(<Route>)
(optional, default[]
)basePath
[String] Prefix for all paths (optional, default''
)
Examples
import { routesCreater as createRoutes } from 'react-router-sitemap';
import { routesParser as parseRoutes } from 'react-router-sitemap';
const routes = createRoutes(<Route path='/home'>);
const paths = parseRoutes(routes); // ['/home']
import { routesCreater as createRoutes } from 'react-router-sitemap';
import { routesParser as parseRoutes } from 'react-router-sitemap';
const routes = createRoutes(<Route path='/home'>);
const prefix = '/prefix';
const paths = parseRoutes(routes, prefix); // ['/prefix/home']
Returns Array<String> Array of paths
Module for building a sitemap using an array of paths. Uses the sitemap package.
Parameters
Examples
import { sitemapBuilder as buildSitemap } from 'react-router-sitemap';
const paths = ['/', 'home', '/contacts'];
const hostname = 'http://may-site.ru';
const sitemap = buildSitemap(hostname, paths);
Returns Sitemap instance of Sitemap.