kuflash / react-router-sitemap

Generate sitemap.xml by React Router configuration
MIT License
251 stars 57 forks source link

There's no possible to generate all links based on the routes #86

Closed francisrod01 closed 5 years ago

francisrod01 commented 5 years ago

There's no possible to generate all links based on the routes, because I had to created a new route-list without import any component. (just links)

Envs:

import React from 'react';
import { Route, Redirect } from 'react-router';

export default (
  <Route>
    <Route path="/" />
    <Route path="/about" />
    <Route path="/contact" />
    <Route path="/company/:id" />
    <Route path="/know-more" />
    <Route path="/cities">
      <Route path='/:slug'>
        <Route path='/event/:eventSlug' />
        <Route path='/ads' />
      </Route>
    </Route>
  </Route>
);

@kuflash What I could do to solve the param problem? Using database to list those urls?

<url> <loc>https://my-page.net/</loc> </url>
<url> <loc>https://my-page.net/about</loc> </url>
<url> <loc>https://my-page.net/contact</loc> </url>
<url> <loc>https://my-page.net/company/:id</loc> </url>
<url> <loc>https://my-page.net/know-more/business</loc> </url>
<url> <loc>https://my-page.net/city-promotion</loc> </url>
<url> <loc>https://my-page.net/city-promotion/:slug</loc> </url>
<url> <loc>https://my-page.net/city-promotion/:slug/event/:eventSlug</loc> </url>
<url> <loc>https://my-page.net/city-promotion/:slug/ad-sample</loc> </url>
kuflash commented 5 years ago

@francisrod01 yes, if you use dynamic routes you need load data for this routes. You can load it's from DB and create rules for mapping data to dynamic routes. Example creating this params stored in example file.

Some pseudocode:

fetch('https://example.com/data-for-routes.json')
  .then((response) => {
    const paramsConfig = {
    '/company/:id': [
      { id: response.ids }, // array of ids
    ],
        '/cities/:slug/event/:eventSlug': [{
          slug: response.slugs, // array of slugs
          eventSlug: response.eventSlugs, // array of event slugs
        }],
    };
    new Sitemap(router)
      .applyParams(paramsConfig)
      .build('http://my-site.ru', { limitCountPaths: 5000 })
      .save('./sitemap.xml', '/static/')
  });

Also, you can read docs.

kuflash commented 5 years ago

@francisrod01 did you have to figure it out?

francisrod01 commented 5 years ago

@kuflash I'll see it tomorrow and go back with the answer. Thanks! :)

The-Code-Monkey says: https://github.com/kuflash/react-router-sitemap/issues/85#issuecomment-462902779

There is you just have to do a fetch with a dB call that gets the slugs from your dB and format it in the way for params to work I'll show you our setup at work tomorrow when I do it for out latest project

Yes, I know. Before to implement that I've been creating a table structure separating all the SEO including all slugs related by the topics. That way prevents I created a VIEW or something else in MongoDB further to indexes for performance of millions of links.

kuflash commented 5 years ago

@francisrod01 unfortunately I can not understand what your problem. If you have all data in MongoDB, why you don't create connect to it and get all data for generate sitemap? Script for build sitemap is run once to create the XML file, and not for each sitemap request, for example, by a robot.

francisrod01 commented 5 years ago

@kuflash I mentioned I'll create that. I think this is the best solution to do that so I'll close for now.