@@ -100,6 +100,19 @@ function parseFileIntoEntity(skyAppConfig, file, index) {
100
100
} ;
101
101
}
102
102
103
+ function generateRedirects ( skyAppConfig ) {
104
+ let redirects = [ ] ;
105
+ if ( skyAppConfig . skyux && skyAppConfig . skyux . redirects ) {
106
+ redirects = Object . keys ( skyAppConfig . skyux . redirects ) . map ( key =>
107
+ `{
108
+ path: '${ key } ',
109
+ redirectTo: '${ skyAppConfig . skyux . redirects [ key ] } '
110
+ }` ) ;
111
+ }
112
+
113
+ return redirects ;
114
+ }
115
+
103
116
function generateRoutes ( skyAppConfig ) {
104
117
let counter = 0 ;
105
118
let entities = glob
@@ -231,7 +244,7 @@ function mergeRoutes(routes) {
231
244
return uniqueRoutes ;
232
245
}
233
246
234
- function generateDeclarations ( routes ) {
247
+ function generateDeclarations ( skyAppConfig , routes ) {
235
248
let mappedRoutes = mergeRoutes ( routes . map ( r => parseRoute ( r ) ) ) ;
236
249
237
250
// nest all routes under a top-level route to allow for app-wide guard
@@ -253,8 +266,10 @@ function generateDeclarations(routes) {
253
266
254
267
// reset root route path to ''
255
268
rootRoute . routePath = '' ;
256
- const declarations = baseRoutes
257
- . map ( r => generateRouteDeclaration ( r ) )
269
+
270
+ // Redirects need to be before '**' catch all
271
+ let declarations = generateRedirects ( skyAppConfig )
272
+ . concat ( baseRoutes . map ( r => generateRouteDeclaration ( r ) ) )
258
273
. join ( ',\n' ) ;
259
274
260
275
return `[\n${ declarations } \n]` ;
@@ -289,7 +304,7 @@ function getRoutesForConfig(routes) {
289
304
function getRoutes ( skyAppConfig ) {
290
305
const routes = generateRoutes ( skyAppConfig ) ;
291
306
return {
292
- declarations : generateDeclarations ( routes ) ,
307
+ declarations : generateDeclarations ( skyAppConfig , routes ) ,
293
308
definitions : generateDefinitions ( routes ) ,
294
309
imports : generateRuntimeImports ( skyAppConfig , routes ) ,
295
310
providers : generateProviders ( routes ) ,
0 commit comments