kuflash / react-router-sitemap

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

Doesn't work for dual dynamic routes #87

Closed The-Code-Monkey closed 5 years ago

The-Code-Monkey commented 5 years ago

if i have /course/:category/:course and do the mapping like

'/courses/:category/:course': [
    { category: ['unknown1', 'unknown2'], course: ['third-project', 'fourth-project'] },
  ],

this outputs:

<url> <loc>http://www.brightonsbm.com/courses/unknown1/third-project</loc> </url>
<url> <loc>http://www.brightonsbm.com/courses/unknown2/third-project</loc> </url>
<url> <loc>http://www.brightonsbm.com/courses/unknown1/fourth-project</loc> </url>
<url> <loc>http://www.brightonsbm.com/courses/unknown2/fourth-project</loc> </url>

rather than:

<url> <loc>http://www.brightonsbm.com/courses/unknown1/third-project</loc> </url>
<url> <loc>http://www.brightonsbm.com/courses/unknown2/fourth-project</loc> </url>

how would i do the second one or is it not possible at the moment??

also could this work for longer urls as i have some that have 3 or 4 dynamic urls

kuflash commented 5 years ago

@The-Code-Monkey for this cases you should use this construction rule:

const paramsConfig = {
    '/courses/:category/:course': [{
        category: 'unknown1',
        course: 'third-project'
    }, {
        category: 'unknown2',
        course: 'fourth-project'
    }],
};

If you have 3 or more dynamic route parts, the rules will look like this:

const paramsConfig = {
    '/courses/:category/:course/:thirdDynamicPart': [{
        category: 'unknown1',
        course: 'third-project',
                thirdDynamicPart: 'something'
    }, {
        category: 'unknown2',
        course: 'fourth-project',
                thirdDynamicPart: 'something'
    }],
};
The-Code-Monkey commented 5 years ago

Thanks