1
1
import util from '../../shared/util.ts'
2
2
import type { RouterURL } from '../../types.d.ts'
3
- import { redirect } from './redirect.ts'
4
3
5
4
const ghostRoute : Route = { path : '' , module : '' }
6
5
@@ -16,6 +15,7 @@ export type RoutingOptions = {
16
15
locales ?: string [ ]
17
16
routes ?: Route [ ]
18
17
rewrites ?: Record < string , string >
18
+ redirect ?: ( url : string , replace ?: boolean ) => void
19
19
}
20
20
21
21
export class Routing {
@@ -24,19 +24,22 @@ export class Routing {
24
24
private _locales : string [ ]
25
25
private _routes : Route [ ]
26
26
private _rewrites ?: Record < string , string >
27
+ private _redirect ?: ( url : string , replace ?: boolean ) => void
27
28
28
29
constructor ( {
29
30
basePath = '/' ,
30
31
defaultLocale = 'en' ,
31
32
locales = [ ] ,
32
33
routes = [ ] ,
33
- rewrites
34
+ rewrites,
35
+ redirect
34
36
} : RoutingOptions = { } ) {
35
37
this . _basePath = basePath
36
38
this . _defaultLocale = defaultLocale
37
39
this . _locales = locales
38
40
this . _routes = routes
39
41
this . _rewrites = rewrites
42
+ this . _redirect = redirect
40
43
}
41
44
42
45
get basePath ( ) {
@@ -179,8 +182,8 @@ export class Routing {
179
182
const qs = this . query . toString ( )
180
183
return [ this . pathname , qs ] . filter ( Boolean ) . join ( '?' )
181
184
} ,
182
- push : ( url : string ) => redirect ( url ) ,
183
- replace : ( url : string ) => redirect ( url , true ) ,
185
+ push : ( url : string ) => this . _redirect && this . _redirect ( url ) ,
186
+ replace : ( url : string ) => this . _redirect && this . _redirect ( url , true ) ,
184
187
} ,
185
188
nestedModules
186
189
]
0 commit comments