13
13
#if LEGACYASPNET
14
14
using System . Web ;
15
15
using IHtmlHelper = System . Web . Mvc . HtmlHelper ;
16
+ using IUrlHelper = System . Web . Mvc . UrlHelper ;
16
17
#else
17
18
using Microsoft . AspNetCore . Mvc . Rendering ;
18
19
using Microsoft . AspNetCore . Html ;
19
20
using IHtmlString = Microsoft . AspNetCore . Html . IHtmlContent ;
21
+ using Microsoft . AspNetCore . Mvc ;
20
22
#endif
21
23
22
24
#if LEGACYASPNET
@@ -148,7 +150,7 @@ public static IHtmlString ReactWithInit<T>(
148
150
{
149
151
Environment . ReturnEngineToPool ( ) ;
150
152
}
151
- }
153
+ }
152
154
153
155
/// <summary>
154
156
/// Renders the JavaScript required to initialise all components client-side. This will
@@ -174,26 +176,28 @@ public static IHtmlString ReactInitJavaScript(this IHtmlHelper htmlHelper, bool
174
176
/// Returns script tags based on the webpack asset manifest
175
177
/// </summary>
176
178
/// <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>
177
180
/// <returns></returns>
178
- public static IHtmlString ReactGetScriptPaths ( this IHtmlHelper htmlHelper )
181
+ public static IHtmlString ReactGetScriptPaths ( this IHtmlHelper htmlHelper , IUrlHelper urlHelper = null )
179
182
{
180
183
string nonce = Environment . Configuration . ScriptNonceProvider != null
181
184
? $ " nonce=\" { Environment . Configuration . ScriptNonceProvider ( ) } \" "
182
185
: "" ;
183
186
184
187
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>") ) ) ;
186
189
}
187
190
188
191
/// <summary>
189
192
/// Returns style tags based on the webpack asset manifest
190
193
/// </summary>
191
194
/// <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>
192
196
/// <returns></returns>
193
- public static IHtmlString ReactGetStylePaths ( this IHtmlHelper htmlHelper )
197
+ public static IHtmlString ReactGetStylePaths ( this IHtmlHelper htmlHelper , IUrlHelper urlHelper = null )
194
198
{
195
199
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 ) ) } \" />") ) ) ;
197
201
}
198
202
199
203
private static IHtmlString RenderToString ( Action < StringWriter > withWriter )
0 commit comments