Filter function should receive the full route object (instead of just the url)

SnirShechter
3
SnirShechter
commented 10 months ago

What problem does this feature solve?

The filter function receives an array of routes containing URLs and sitemap options. This means that the only way to filter the route is by final URL:

filter function - received route object

{
      url:'/about-us',
      // ...sitemapOptions
}

The specific need rises when we are using nuxt-i18n:

localed route

routeName: 'about'
urls:{
      en: '/about-us', 
      fr: '/a-propos',
      es: '/sobre' 
}

If I wish to exclude these routes, I need to use one of two options:

sitemapConfig - exclude 'about'

exclude: [
      '/about-us', 
      '/a-propos',
      '/sobre'
]

or

filter function - exclude 'about'

filter(routes){
      const excludedRoutes =  ['/about-us', '/a-propos', '/sobre']
      return routes.filter(route=>!excludedRoutes.includes(route.url))
}

What does the proposed changes look like?

The route object can actually contain more data:

filter function - possible route object

{
      url:'/about-us',
      name:'about',
      path:'/',
      chunkName:'pages/index',
      component:'C:\dev\sitemap-module\test\fixture\pages\about.vue'
}

Using that data, we can easily exclude routes by name.

filter function - new form

filter(routes){
      const excludedRouteNames =  ['about']
      return routes.filter(route=>!excludedRouteNames .includes(route.name))
}
idea
0
ricardogobbosouza
1.1k
ricardogobbosouza
commented 6 months ago

@SnirShechter, @NicoPennec
In version 2.0.0 the route is coming as an object, I think it can close.

0
ricardogobbosouza
1.1k
ricardogobbosouza
commented 6 months ago

@NicoPennec can closed?

0
NicoPennec
1.7k
NicoPennec
commented 5 months ago

@ricardogobbosouza no, it's not that.

0
NicoPennec
1.7k
NicoPennec
commented 5 months ago

@SnirShechter I just cherry-picked your commit from your still remained opened PR #70

Thank you for this contribution ๐Ÿ™

0
Informations
Feature Request โ€ข Open
#c53 - Created 10 months ago