diff --git a/src/React.Router/HtmlHelperExtensions.cs b/src/React.Router/HtmlHelperExtensions.cs
index 2c33eb8aa..7e8df2c33 100644
--- a/src/React.Router/HtmlHelperExtensions.cs
+++ b/src/React.Router/HtmlHelperExtensions.cs
@@ -53,8 +53,40 @@ private static IReactEnvironment Environment
/// Skip rendering React specific data-attributes during server side rendering. Defaults to false
/// HTML class(es) to set on the container tag
/// containing the rendered markup for provided React Router component
+ [Obsolete("Please use Html.ReactRouter instead")]
public static IHtmlString ReactRouterWithContext(
- this IHtmlHelper htmlHelper,
+ this IHtmlHelper htmlHelper,
+ string componentName,
+ T props,
+ string path = null,
+ string htmlTag = null,
+ string containerId = null,
+ bool clientOnly = false,
+ bool serverOnly = false,
+ string containerClass = null,
+ Action contextHandler = null
+ )
+ {
+ return ReactRouter(htmlHelper, componentName, props, path, htmlTag, containerId, clientOnly, serverOnly, containerClass, contextHandler);
+ }
+
+ ///
+ /// Render a React StaticRouter Component with context object.
+ /// Can optionally be provided with a custom context handler to handle the various status codes.
+ ///
+ /// MVC Razor
+ /// Name of React Static Router component. Expose component globally to ReactJS.NET
+ /// Props to initialise the component with
+ /// F.x. from Request.Path. Used by React Static Router to determine context and routing.
+ /// Optional custom context handler, can be used instead of providing a Response object
+ /// HTML tag to wrap the component in. Defaults to <div>
+ /// ID to use for the container HTML tag. Defaults to an auto-generated ID
+ /// Skip rendering server-side and only output client-side initialisation code. Defaults to false
+ /// Skip rendering React specific data-attributes during server side rendering. Defaults to false
+ /// HTML class(es) to set on the container tag
+ /// containing the rendered markup for provided React Router component
+ public static IHtmlString ReactRouter(
+ this IHtmlHelper htmlHelper,
string componentName,
T props,
string path = null,
@@ -71,12 +103,12 @@ public static IHtmlString ReactRouterWithContext(
var response = htmlHelper.ViewContext.HttpContext.Response;
path = path ?? htmlHelper.ViewContext.HttpContext.Request.Path;
- var reactComponent
+ var reactComponent
= Environment.CreateRouterComponent(
- componentName,
- props,
- path,
- containerId,
+ componentName,
+ props,
+ path,
+ containerId,
clientOnly
);
@@ -88,7 +120,7 @@ var reactComponent
{
reactComponent.ContainerClass = containerClass;
}
-
+
var executionResult = reactComponent.RenderRouterWithContext(clientOnly, serverOnly);
if (executionResult.Context?.status != null)
diff --git a/tests/React.Tests/Router/HtmlHelperExtensionsTest.cs b/tests/React.Tests/Router/HtmlHelperExtensionsTest.cs
index 7ccaf6230..9f34b5d68 100644
--- a/tests/React.Tests/Router/HtmlHelperExtensionsTest.cs
+++ b/tests/React.Tests/Router/HtmlHelperExtensionsTest.cs
@@ -116,7 +116,7 @@ public void EngineIsReturnedToPoolAfterRender()
var htmlHelperMock = new HtmlHelperMocks();
environment.Verify(x => x.ReturnEngineToPool(), Times.Never);
- var result = HtmlHelperExtensions.ReactRouterWithContext(
+ var result = HtmlHelperExtensions.ReactRouter(
htmlHelper: htmlHelperMock.htmlHelper.Object,
componentName: "ComponentName",
props: new { },
@@ -137,7 +137,7 @@ public void ReactWithClientOnlyTrueShouldCallRenderHtmlWithTrue()
var environment = ConfigureMockEnvironment();
var routerMocks = new ReactRouterMocks(config, environment);
- var result = HtmlHelperExtensions.ReactRouterWithContext(
+ var result = HtmlHelperExtensions.ReactRouter(
htmlHelper: htmlHelperMock.htmlHelper.Object,
componentName: "ComponentName",
props: new { },
@@ -158,7 +158,7 @@ public void ReactWithServerOnlyTrueShouldCallRenderHtmlWithTrue()
var environment = ConfigureMockEnvironment();
var routerMocks = new ReactRouterMocks(config, environment);
- var result = HtmlHelperExtensions.ReactRouterWithContext(
+ var result = HtmlHelperExtensions.ReactRouter(
htmlHelper: htmlHelperMock.htmlHelper.Object,
componentName: "ComponentName",
props: new { },
@@ -181,7 +181,7 @@ public void ShouldModifyStatusCode()
var htmlHelperMock = new HtmlHelperMocks();
- HtmlHelperExtensions.ReactRouterWithContext(
+ HtmlHelperExtensions.ReactRouter(
htmlHelper: htmlHelperMock.htmlHelper.Object,
componentName: "ComponentName",
props: new { },
@@ -201,7 +201,7 @@ public void ShouldRunCustomContextHandler()
var htmlHelperMock = new HtmlHelperMocks();
- HtmlHelperExtensions.ReactRouterWithContext(
+ HtmlHelperExtensions.ReactRouter(
htmlHelper: htmlHelperMock.htmlHelper.Object,
componentName: "ComponentName",
props: new { },
@@ -222,7 +222,7 @@ public void ShouldRedirectPermanent()
var htmlHelperMock = new HtmlHelperMocks();
- HtmlHelperExtensions.ReactRouterWithContext(
+ HtmlHelperExtensions.ReactRouter(
htmlHelper: htmlHelperMock.htmlHelper.Object,
componentName: "ComponentName",
props: new { },
@@ -244,7 +244,7 @@ public void ShouldFailRedirectWithNoUrl()
Assert.Throws(() =>
- HtmlHelperExtensions.ReactRouterWithContext(
+ HtmlHelperExtensions.ReactRouter(
htmlHelper: htmlHelperMock.htmlHelper.Object,
componentName: "ComponentName",
props: new { },