@@ -2,35 +2,53 @@ import {
22 MODULE_NAME ,
33 STRATEGIES } from './constants'
44import { extractComponentOptions } from './components'
5- import { getLocaleCodes } from './utils'
5+ import { getPageOptions , getLocaleCodes } from './utils'
66
77export const makeRoutes = ( baseRoutes , {
88 locales,
99 defaultLocale,
1010 routesNameSeparator,
1111 strategy,
12+ parsePages,
13+ pages,
14+ pagesDir,
1215 differentDomains
1316} ) => {
1417 locales = getLocaleCodes ( locales )
1518 let localizedRoutes = [ ]
1619
1720 const buildLocalizedRoutes = ( route , routeOptions = { } , isChild = false ) => {
1821 const routes = [ ]
22+ let pageOptions
1923
2024 // Extract i18n options from page
21- const extractedOptions = extractComponentOptions ( route . component )
25+ if ( parsePages ) {
26+ pageOptions = extractComponentOptions ( route . component )
27+ } else {
28+ pageOptions = getPageOptions ( route , pages , locales , pagesDir )
29+ }
2230
2331 // Skip route if i18n is disabled on page
24- if ( extractedOptions === false ) {
32+ if ( pageOptions === false ) {
2533 return route
2634 }
2735
2836 // Component's specific options
2937 const componentOptions = {
3038 locales,
31- ...extractComponentOptions ( route . component ) ,
39+ ...pageOptions ,
3240 ...routeOptions
3341 }
42+ // Double check locales to remove any locales not found in pageOptions
43+ // This is there to prevent children routes being localized even though
44+ // they are disabled in the configuration
45+ if (
46+ typeof componentOptions . locales !== 'undefined' && componentOptions . locales . length > 0 &&
47+ typeof pageOptions . locales !== 'undefined' && pageOptions . locales . length > 0 ) {
48+ componentOptions . locales = componentOptions . locales . filter ( ( locale ) => (
49+ pageOptions . locales . indexOf ( locale ) !== - 1
50+ ) )
51+ }
3452
3553 // Generate routes for component's supported locales
3654 for ( let i = 0 , length1 = componentOptions . locales . length ; i < length1 ; i ++ ) {
@@ -82,7 +100,7 @@ export const makeRoutes = (baseRoutes, {
82100
83101 for ( let i = 0 , length1 = baseRoutes . length ; i < length1 ; i ++ ) {
84102 const route = baseRoutes [ i ]
85- localizedRoutes = localizedRoutes . concat ( buildLocalizedRoutes ( route , locales ) )
103+ localizedRoutes = localizedRoutes . concat ( buildLocalizedRoutes ( route , { locales } ) )
86104 }
87105
88106 return localizedRoutes
0 commit comments