@@ -115,24 +115,55 @@ public ActionResult<NavMenu> GetLeftNav(bool area = true, string nav = "viper-ho
115115 return menu ;
116116 }
117117
118+ /// <summary>
119+ /// For the development environment, links starting with '/' (but not /2) need to be changed to use http://localhost
120+ /// (Viper 2 will be using https locally with a custom port)
121+ /// </summary>
122+ /// <param name="menu"></param>
118123 private static void ConvertNavLinksForDevelopment ( NavMenu menu )
119124 {
120125 if ( HttpHelper . Environment ? . EnvironmentName == "Development" && menu ? . MenuItems != null )
121126 {
122- foreach ( var item in menu . MenuItems . Where ( item => item . MenuItemURL . Length > 0 && item . MenuItemURL . Substring ( 0 , 1 ) == "/" ) )
127+ foreach ( var item in menu . MenuItems . Where ( item => item . MenuItemURL . Length > 0
128+ && item . MenuItemURL [ ..1 ] == "/"
129+ && ( item . MenuItemURL . Length < 2 || item . MenuItemURL [ ..2 ] != "/2" ) ) )
123130 {
124131 item . MenuItemURL = "http://localhost" + item . MenuItemURL ;
125132 }
126133 }
127134 }
128135
136+ /// <summary>
137+ /// Modify the base path to handle two cases:
138+ /// Links starting with "/" are VIPER 1.0 links and should be changed to start with https://{{host}}/, otherwise they will point to /2/
139+ /// Links starting with "~/" or "/2" are VIPER 2.0 links and should be changed to start with "/"
140+ /// </summary>
141+ /// <param name="menu"></param>
129142 private static void AdjustBasePath ( NavMenu menu )
130143 {
131144 if ( menu . MenuItems != null )
132145 {
133- foreach ( var item in menu . MenuItems . Where ( item => item . MenuItemURL . Length > 0 && item . MenuItemURL . Substring ( 0 , 2 ) == "~/" ) )
146+ var viper1 = HttpHelper . GetOldViperRootURL ( ) ;
147+
148+ // Fix VIPER 1.0 links
149+ foreach ( var item in menu . MenuItems . Where ( item => item . MenuItemURL . Length > 0
150+ && item . MenuItemURL [ ..1 ] == "/"
151+ && ( item . MenuItemURL . Length < 2 || item . MenuItemURL [ ..2 ] != "/2" ) ) )
152+ {
153+ item . MenuItemURL = $ "{ viper1 } { item . MenuItemURL } ";
154+ }
155+
156+ // Fix VIPER 2.0 links
157+ foreach ( var item in menu . MenuItems . Where ( item => item . MenuItemURL . Length > 1 ) )
134158 {
135- item . MenuItemURL = item . MenuItemURL . Replace ( "~/" , "/" ) ;
159+ if ( item . MenuItemURL [ ..2 ] == "~/" )
160+ {
161+ item . MenuItemURL = item . MenuItemURL [ 1 ..] ; //strip '~'
162+ }
163+ else if ( item . MenuItemURL [ ..2 ] == "/2" )
164+ {
165+ item . MenuItemURL = ( item . MenuItemURL . Length > 2 ? item . MenuItemURL [ 2 ..] : "" ) ; //strip '/2'
166+ }
136167 }
137168 }
138169 }
0 commit comments