Skip to content

Commit

Permalink
feat: do not generate index route on pix.fr to avoid conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbertrand authored and VincentHardouin committed Jan 6, 2023
1 parent 410d0de commit b96a3f1
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { transports } from 'winston'
import routes from './services/get-routes-to-generate'
import { filterNuxtPages } from './services/filter-nuxt-pages'
import { language } from './config/language'
import { config } from './config/environment'
import { SITES_PRISMIC_TAGS } from './services/available-sites'
Expand Down Expand Up @@ -180,6 +181,9 @@ const nuxtConfig = {
router: {
middleware: ['current-page-path'],
linkExactActiveClass: 'current-active-link',
extendRoutes(routes) {
return filterNuxtPages(routes, config)
},
},

/*
Expand Down
9 changes: 9 additions & 0 deletions services/filter-nuxt-pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function filterNuxtPages(routes, config) {
if (config.isPixSite && config.isFrenchDomain) {
return routes.filter(
(route) => !(route.name === 'index' && route.path === '/')
)
}

return routes
}
52 changes: 52 additions & 0 deletions tests/services/filter-nuxt-pages.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { filterNuxtPages } from '~/services/filter-nuxt-pages'

describe('FilterNuxtPages', () => {
describe('when is french domain', () => {
it('should return only locale home at root path', function () {
// given
const config = {
isPixSite: true,
isFrenchDomain: true,
}
const routes = [
{ name: 'locale_home___fr-fr', path: '/' },
{ name: 'index', path: '/' },
{ name: 'foo', path: '/foo' },
]

// when
const filteredRoutes = filterNuxtPages(routes, config)

// then
expect(filteredRoutes).toEqual([
{ name: 'locale_home___fr-fr', path: '/' },
{ name: 'foo', path: '/foo' },
])
})
})

describe('when is international domain', () => {
it('should return routes as is', function () {
// given
const config = {
isPixSite: true,
isFrenchDomain: false,
}
const routes = [
{ name: 'locale_home___fr', path: '/fr/' },
{ name: 'index', path: '/' },
{ name: 'foo', path: '/foo' },
]

// when
const filteredRoutes = filterNuxtPages(routes, config)

// then
expect(filteredRoutes).toEqual([
{ name: 'locale_home___fr', path: '/fr/' },
{ name: 'index', path: '/' },
{ name: 'foo', path: '/foo' },
])
})
})
})

0 comments on commit b96a3f1

Please sign in to comment.