11import { uniq } from 'lodash' ;
22import React from 'react' ;
3+ import { Redirect , RouteComponentProps } from 'react-router-dom' ;
34
45import { SafeDynamicImport } from 'app/core/components/DynamicImports/SafeDynamicImport' ;
56import { NavLandingPage } from 'app/core/components/NavLandingPage/NavLandingPage' ;
@@ -14,73 +15,79 @@ const commonRoutes: RouteDescriptor[] = [];
1415const legacyRoutes : RouteDescriptor [ ] = [
1516 ...commonRoutes ,
1617 {
17- path : '/alerting' ,
18+ path : '/alerting-legacy ' ,
1819 component : ( ) => < NavLandingPage navId = "alerting-legacy" /> ,
1920 } ,
2021 {
21- path : '/alerting/list' ,
22+ path : '/alerting-legacy /list' ,
2223 component : SafeDynamicImport (
23- ( ) => import ( /* webpackChunkName: "AlertRuleListIndex " */ 'app/features/alerting/AlertRuleList' )
24+ ( ) => import ( /* webpackChunkName: "AlertRuleListLegacyIndex " */ 'app/features/alerting/AlertRuleList' )
2425 ) ,
2526 } ,
2627 {
27- path : '/alerting/ng/list' ,
28+ path : '/alerting-legacy /ng/list' ,
2829 component : SafeDynamicImport (
29- ( ) => import ( /* webpackChunkName: "AlertRuleList " */ 'app/features/alerting/AlertRuleList' )
30+ ( ) => import ( /* webpackChunkName: "AlertRuleListLegacy " */ 'app/features/alerting/AlertRuleList' )
3031 ) ,
3132 } ,
3233 {
33- path : '/alerting/notifications' ,
34+ path : '/alerting-legacy /notifications' ,
3435 roles : config . unifiedAlertingEnabled ? ( ) => [ 'Editor' , 'Admin' ] : undefined ,
3536 component : SafeDynamicImport (
36- ( ) => import ( /* webpackChunkName: "NotificationsListPage " */ 'app/features/alerting/NotificationsListPage' )
37+ ( ) => import ( /* webpackChunkName: "NotificationsListLegacyPage " */ 'app/features/alerting/NotificationsListPage' )
3738 ) ,
3839 } ,
3940 {
40- path : '/alerting/notifications/templates/new' ,
41+ path : '/alerting-legacy /notifications/templates/new' ,
4142 roles : ( ) => [ 'Editor' , 'Admin' ] ,
4243 component : SafeDynamicImport (
43- ( ) => import ( /* webpackChunkName: "NotificationsListPage " */ 'app/features/alerting/NotificationsListPage' )
44+ ( ) => import ( /* webpackChunkName: "NotificationsListLegacyPage " */ 'app/features/alerting/NotificationsListPage' )
4445 ) ,
4546 } ,
4647 {
47- path : '/alerting/notifications/templates/:id/edit' ,
48+ path : '/alerting-legacy /notifications/templates/:id/edit' ,
4849 roles : ( ) => [ 'Editor' , 'Admin' ] ,
4950 component : SafeDynamicImport (
50- ( ) => import ( /* webpackChunkName: "NotificationsListPage " */ 'app/features/alerting/NotificationsListPage' )
51+ ( ) => import ( /* webpackChunkName: "NotificationsListLegacyPage " */ 'app/features/alerting/NotificationsListPage' )
5152 ) ,
5253 } ,
5354 {
54- path : '/alerting/notifications/receivers/new' ,
55+ path : '/alerting-legacy /notifications/receivers/new' ,
5556 roles : ( ) => [ 'Editor' , 'Admin' ] ,
5657 component : SafeDynamicImport (
57- ( ) => import ( /* webpackChunkName: "NotificationsListPage " */ 'app/features/alerting/NotificationsListPage' )
58+ ( ) => import ( /* webpackChunkName: "NotificationsListLegacyPage " */ 'app/features/alerting/NotificationsListPage' )
5859 ) ,
5960 } ,
6061 {
61- path : '/alerting/notifications/receivers/:id/edit' ,
62+ path : '/alerting-legacy /notifications/receivers/:id/edit' ,
6263 roles : ( ) => [ 'Editor' , 'Admin' ] ,
6364 component : SafeDynamicImport (
64- ( ) => import ( /* webpackChunkName: "NotificationsListPage " */ 'app/features/alerting/NotificationsListPage' )
65+ ( ) => import ( /* webpackChunkName: "NotificationsListLegacyPage " */ 'app/features/alerting/NotificationsListPage' )
6566 ) ,
6667 } ,
6768 {
68- path : '/alerting/notifications/global-config' ,
69+ path : '/alerting-legacy /notifications/global-config' ,
6970 roles : ( ) => [ 'Admin' , 'Editor' ] ,
7071 component : SafeDynamicImport (
71- ( ) => import ( /* webpackChunkName: "NotificationsListPage " */ 'app/features/alerting/NotificationsListPage' )
72+ ( ) => import ( /* webpackChunkName: "NotificationsListLegacyPage " */ 'app/features/alerting/NotificationsListPage' )
7273 ) ,
7374 } ,
7475 {
75- path : '/alerting/notification/new' ,
76+ path : '/alerting-legacy /notification/new' ,
7677 component : SafeDynamicImport (
77- ( ) => import ( /* webpackChunkName: "NewNotificationChannel" */ 'app/features/alerting/NewNotificationChannelPage' )
78+ ( ) =>
79+ import (
80+ /* webpackChunkName: "NewNotificationChannelLegacy" */ 'app/features/alerting/NewNotificationChannelPage'
81+ )
7882 ) ,
7983 } ,
8084 {
81- path : '/alerting/notification/:id/edit' ,
85+ path : '/alerting-legacy /notification/:id/edit' ,
8286 component : SafeDynamicImport (
83- ( ) => import ( /* webpackChunkName: "EditNotificationChannel"*/ 'app/features/alerting/EditNotificationChannelPage' )
87+ ( ) =>
88+ import (
89+ /* webpackChunkName: "EditNotificationChannelLegacy"*/ 'app/features/alerting/EditNotificationChannelPage'
90+ )
8491 ) ,
8592 } ,
8693] ;
@@ -295,7 +302,32 @@ export function getAlertingRoutes(cfg = config): RouteDescriptor[] {
295302 if ( cfg . unifiedAlertingEnabled ) {
296303 return unifiedRoutes ;
297304 } else if ( cfg . alertingEnabled ) {
298- return legacyRoutes ;
305+ // Redirect old overlapping legacy routes to new separate ones to minimize unintended 404s.
306+ const redirects = [
307+ {
308+ path : '/alerting' ,
309+ component : ( ) => < Redirect to = { '/alerting-legacy' } /> ,
310+ } ,
311+ {
312+ path : '/alerting/list' ,
313+ component : ( ) => < Redirect to = { '/alerting-legacy/list' } /> ,
314+ } ,
315+ {
316+ path : '/alerting/notifications' ,
317+ component : ( ) => < Redirect to = { '/alerting-legacy/notifications' } /> ,
318+ } ,
319+ {
320+ path : '/alerting/notification/new' ,
321+ component : ( ) => < Redirect to = { '/alerting-legacy/notification/new' } /> ,
322+ } ,
323+ {
324+ path : '/alerting/notification/:id/edit' ,
325+ component : ( props : RouteComponentProps < { id : string } > ) => (
326+ < Redirect to = { '/alerting-legacy/notification/:id/edit' . replace ( ':id' , props . match . params . id ) } />
327+ ) ,
328+ } ,
329+ ] ;
330+ return [ ...legacyRoutes , ...redirects ] ;
299331 }
300332
301333 const uniquePaths = uniq ( [ ...legacyRoutes , ...unifiedRoutes ] . map ( ( route ) => route . path ) ) ;
0 commit comments