1313#if LEGACYASPNET
1414using System . Web ;
1515using IHtmlHelper = System . Web . Mvc . HtmlHelper ;
16+ using IUrlHelper = System . Web . Mvc . UrlHelper ;
1617#else
1718using Microsoft . AspNetCore . Mvc . Rendering ;
1819using Microsoft . AspNetCore . Html ;
1920using IHtmlString = Microsoft . AspNetCore . Html . IHtmlContent ;
21+ using Microsoft . AspNetCore . Mvc ;
2022#endif
2123
2224#if LEGACYASPNET
@@ -148,7 +150,7 @@ public static IHtmlString ReactWithInit<T>(
148150 {
149151 Environment . ReturnEngineToPool ( ) ;
150152 }
151- }
153+ }
152154
153155 /// <summary>
154156 /// Renders the JavaScript required to initialise all components client-side. This will
@@ -174,26 +176,28 @@ public static IHtmlString ReactInitJavaScript(this IHtmlHelper htmlHelper, bool
174176 /// Returns script tags based on the webpack asset manifest
175177 /// </summary>
176178 /// <param name="htmlHelper"></param>
179+ /// <param name="urlHelper">Optional IUrlHelper instance. Enables the use of tilde/relative (~/) paths inside the expose-components.js file.</param>
177180 /// <returns></returns>
178- public static IHtmlString ReactGetScriptPaths ( this IHtmlHelper htmlHelper )
181+ public static IHtmlString ReactGetScriptPaths ( this IHtmlHelper htmlHelper , IUrlHelper urlHelper = null )
179182 {
180183 string nonce = Environment . Configuration . ScriptNonceProvider != null
181184 ? $ " nonce=\" { Environment . Configuration . ScriptNonceProvider ( ) } \" "
182185 : "" ;
183186
184187 return new HtmlString ( string . Join ( "" , Environment . GetScriptPaths ( )
185- . Select ( scriptPath => $ "<script{ nonce } src=\" { scriptPath } \" ></script>") ) ) ;
188+ . Select ( scriptPath => $ "<script{ nonce } src=\" { ( urlHelper == null ? scriptPath : urlHelper . Content ( scriptPath ) ) } \" ></script>") ) ) ;
186189 }
187190
188191 /// <summary>
189192 /// Returns style tags based on the webpack asset manifest
190193 /// </summary>
191194 /// <param name="htmlHelper"></param>
195+ /// <param name="urlHelper">Optional IUrlHelper instance. Enables the use of tilde/relative (~/) paths inside the expose-components.js file.</param>
192196 /// <returns></returns>
193- public static IHtmlString ReactGetStylePaths ( this IHtmlHelper htmlHelper )
197+ public static IHtmlString ReactGetStylePaths ( this IHtmlHelper htmlHelper , IUrlHelper urlHelper = null )
194198 {
195199 return new HtmlString ( string . Join ( "" , Environment . GetStylePaths ( )
196- . Select ( stylePath => $ "<link rel=\" stylesheet\" href=\" { stylePath } \" />") ) ) ;
200+ . Select ( stylePath => $ "<link rel=\" stylesheet\" href=\" { ( urlHelper == null ? stylePath : urlHelper . Content ( stylePath ) ) } \" />") ) ) ;
197201 }
198202
199203 private static IHtmlString RenderToString ( Action < StringWriter > withWriter )
0 commit comments