Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit b8786a6

Browse files
committed
Update routing options
1 parent 0f2713f commit b8786a6

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

framework/core/routing.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import util from '../../shared/util.ts'
2-
import type { RouterURL } from '../../types.d.ts'
2+
import type { Config, RouterURL } from '../../types.d.ts'
33

44
const ghostRoute: Route = { path: '', module: '' }
55

@@ -9,12 +9,9 @@ export type Route = {
99
children?: Route[]
1010
}
1111

12-
export type RoutingOptions = {
13-
basePath?: string
14-
defaultLocale?: string
15-
locales?: string[]
16-
routes?: Route[]
12+
export type RoutingOptions = Pick<Config, 'basePath' | 'i18n'> & {
1713
rewrites?: Record<string, string>
14+
routes?: Route[]
1815
redirect?: (url: string, replace?: boolean) => void
1916
}
2017

@@ -28,17 +25,16 @@ export class Routing {
2825

2926
constructor({
3027
basePath = '/',
31-
defaultLocale = 'en',
32-
locales = [],
28+
i18n = { defaultLocale: 'en', locales: [] },
3329
routes = [],
3430
rewrites,
35-
redirect
31+
redirect,
3632
}: RoutingOptions = {}) {
3733
this._basePath = basePath
38-
this._defaultLocale = defaultLocale
39-
this._locales = locales
40-
this._routes = routes
34+
this._defaultLocale = i18n.defaultLocale || 'en'
35+
this._locales = i18n.locales
4136
this._rewrites = rewrites
37+
this._routes = routes
4238
this._redirect = redirect
4339
}
4440

framework/react/bootstrap.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import Router, { createPageRoute, importPageModules } from './components/Router.
77
import { loadSSRDataFromTag, setStaticDataRoutes } from './pagedata.ts'
88

99
type BootstrapOptions = Required<RoutingOptions> & {
10+
renderMode: 'ssr' | 'spa',
1011
dataRoutes?: string[],
1112
appModule?: string,
12-
renderMode: 'ssr' | 'spa'
1313
}
1414

1515
export default async function bootstrap(options: BootstrapOptions) {
16-
const { basePath, defaultLocale, locales, appModule: appModuleSpcifier, routes, dataRoutes, rewrites, renderMode } = options
16+
const { basePath, i18n, appModule: appModuleSpcifier, routes, dataRoutes, rewrites, renderMode } = options
1717
const { document } = window as any
1818
const appModule = appModuleSpcifier ? await importModule(basePath, appModuleSpcifier) : {}
19-
const routing = new Routing({ routes, rewrites, basePath, defaultLocale, locales, redirect })
19+
const routing = new Routing({ basePath, i18n, rewrites, routes, redirect })
2020
const [url, nestedModules] = routing.createRouter()
2121
const components = await importPageModules(url, nestedModules)
2222

server/aleph.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,13 @@ export class Aleph implements IAleph {
105105
Object.assign(this.#importMap, getDefaultImportMap())
106106
}
107107
if (configFile) {
108-
const config = await loadConfig(configFile)
109-
Object.assign(this.#config, config, config.i18n)
110-
this.#pageRouting = new Routing(this.#config)
108+
Object.assign(this.#config, await loadConfig(configFile))
109+
const { basePath, i18n, server: { rewrites } } = this.#config
110+
this.#pageRouting = new Routing({
111+
basePath,
112+
i18n,
113+
rewrites,
114+
})
111115
}
112116

113117
await fixConfig(this.#workingDir, this.#config, this.#importMap)
@@ -660,16 +664,15 @@ export class Aleph implements IAleph {
660664
async createMainJS(bundleMode = false): Promise<string> {
661665
const alephPkgUri = getAlephPkgUri()
662666
const alephPkgPath = alephPkgUri.replace('https://', '').replace('http://localhost:', 'http_localhost_')
663-
const { framework, basePath: basePath, i18n: { defaultLocale, locales } } = this.#config
667+
const { framework, basePath, i18n, ssr, server: { rewrites } } = this.#config
664668
const { routes } = this.#pageRouting
665669
const config: Record<string, any> = {
670+
renderMode: ssr ? 'ssr' : 'spa',
666671
basePath,
667672
appModule: this.#appModule?.specifier,
668673
routes,
669-
renderMode: this.#config.ssr ? 'ssr' : 'spa',
670-
defaultLocale,
671-
locales,
672-
rewrites: this.#config.server.rewrites,
674+
i18n,
675+
rewrites: rewrites,
673676
}
674677

675678
let code: string

0 commit comments

Comments
 (0)