Is it necessary to reassign Blazor class properties assigned from URL route parameters?

When I first started to learn Blazor the tutorials I followed would reassign the class properties for a page assigned by URL parameters to new class properties like this:

//URL = "/pagename/{parameter1}/{parameter2}"
[Parameter]
public string parameter1 { get; set; }
public string Parameter1 { get; set; }
[Parameter]
public string parameter2 { get; set; }
public string Parameter2 { get; set; }

protected override void OnInitialized()
{
   Parameter1 = parameter1;
   Parameter2 = parameter2;
}

Why would I not just assign the URL parameters to the page's properties I want to use in the first place? This way I avoid the extra code and processing.

//URL = "/pagename/{Parameter1}/{Parameter2}"
[Parameter]
public string Parameter1 { get; set; }
[Parameter]
public string Parameter2 { get; set; }

Is there a reason why I would want to use the first way over the second way? If so what is it?

*Edited for accuracy and clarity as suggested in comments.


Why would I not just assign the URL parameters to the properties I want to use to avoid the extra code and processing like this?

//URL = "/pagename/{Parameter1}/{Parameter2}"

[Parameter]
string Parameter1 { get; set; }
[Parameter]
string Parameter2 { get; set; }

This is precisely how it has always been. Note also that the parameters' names in the route template can start with a lower-case letter (preferable).

Note: A parameter property should be public.


It really depends on what you are doing with the parameters.

The general rule to follow in Blazor is "components shouldn't overwrite their own incoming parameter value properties" - Steve Sanderson's comment on this issue

Blazor tracks parameter state internally and if your component modifies the value of a parameter directly parameter1 = "foo" then "Blazor" does not see that change.

It is not even good enough to include a Parameter1Changed EventCallback to update the parent component as there is still a period of time between you changing the parameter value and the internal state getting updated. This can cause problems with component rendering.

So, if your component is going to update the parameter, you should always copy it to a local field/property first, update the local and the invoke your original Parameter1Changed EventCallback. This will allow any state to be updated.

In the case of URL parameters it is unlikely you would be updating them, but there could be a scenario where you felt it was a good idea - so that is possibly why your tutorials did this tactic of working with a local copy.