Skip to content

Commit e0f32dd

Browse files
authored
Ensure ? is included in path variable. (#1271)
* Ensure ? is included in path variable closes #1270 * Added extra null check on request object
1 parent 6d4a15a commit e0f32dd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/React.Router/HtmlHelperExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ public static IHtmlString ReactRouter<T>(
102102
{
103103
var response = htmlHelper.ViewContext.HttpContext.Response;
104104
var request = htmlHelper.ViewContext.HttpContext.Request;
105-
path = path ?? request.Path.ToString() + request.QueryString;
105+
var queryString = request != null && request.QueryString != null ? request.QueryString.ToString() : "";
106+
if (!string.IsNullOrWhiteSpace(queryString) && !queryString.StartsWith("?"))
107+
{
108+
queryString = $"?{queryString}";
109+
}
110+
path = path ?? request.Path.ToString() + queryString;
106111

107112
var reactComponent
108113
= Environment.CreateRouterComponent(

0 commit comments

Comments
 (0)