3
3
import { importModule } from '../core/module.ts'
4
4
import { Routing , RoutingOptions } from '../core/routing.ts'
5
5
import Router , { createPageRoute } from './components/Router.ts'
6
- import { loadSSRDataFromTag } from './pagedata.ts'
6
+ import { loadSSRDataFromTag , setStaticSsrRoutes } from './pagedata.ts'
7
7
8
8
type BootstrapOptions = Required < RoutingOptions > & {
9
+ ssrRoutes ?: string [ ] ,
9
10
appModule ?: string ,
10
11
renderMode : 'ssr' | 'spa'
11
12
}
12
13
13
14
export default async function bootstrap ( options : BootstrapOptions ) {
14
- const { basePath, defaultLocale, locales, appModule : appModuleSpcifier , routes, rewrites, renderMode } = options
15
+ const { basePath, defaultLocale, locales, appModule : appModuleSpcifier , routes, ssrRoutes , rewrites, renderMode } = options
15
16
const { document } = window as any
16
17
const appModule = appModuleSpcifier ? await importModule ( basePath , appModuleSpcifier ) : { }
17
18
const routing = new Routing ( { routes, rewrites, basePath, defaultLocale, locales } )
@@ -21,23 +22,25 @@ export default async function bootstrap(options: BootstrapOptions) {
21
22
const mountPoint = document . getElementById ( '__aleph' )
22
23
23
24
if ( renderMode === 'ssr' ) {
25
+ if ( ssrRoutes ) {
26
+ setStaticSsrRoutes ( ssrRoutes )
27
+ }
24
28
loadSSRDataFromTag ( url )
25
29
hydrate ( routerEl , mountPoint )
26
30
} else {
27
31
render ( routerEl , mountPoint )
28
32
}
29
33
30
- // remove ssr head elements, set a timmer to avoid the tab title flash
31
- setTimeout ( ( ) => {
32
- Array . from ( document . head . children ) . forEach ( ( el : any ) => {
33
- const tag = el . tagName . toLowerCase ( )
34
- if (
35
- el . hasAttribute ( 'ssr' ) &&
36
- tag !== 'style' &&
37
- ! ( tag === 'link' && el . getAttribute ( 'rel' ) === 'stylesheet' )
38
- ) {
39
- document . head . removeChild ( el )
40
- }
41
- } )
42
- } , 0 )
34
+ // remove ssr head elements
35
+ await Promise . resolve ( )
36
+ Array . from ( document . head . children ) . forEach ( ( el : any ) => {
37
+ const tag = el . tagName . toLowerCase ( )
38
+ if (
39
+ el . hasAttribute ( 'ssr' ) &&
40
+ tag !== 'style' &&
41
+ ! ( tag === 'link' && el . getAttribute ( 'rel' ) === 'stylesheet' )
42
+ ) {
43
+ document . head . removeChild ( el )
44
+ }
45
+ } )
43
46
}
0 commit comments