Home > Net >  Poking fun at a recently developed blazor SPA applications meet the pit
Poking fun at a recently developed blazor SPA applications meet the pit

Time:02-24

I am using Ant Design of Blazor

First of all, I think blazor occasionally one of the biggest problems is the breakpoint, solve the problem of this very vexed, can't debug, can only be found from the stack information inside the bottom where I went wrong,

Less good.net standar API, NuGet standar based on library can also not much,


And navigation, in the current page to navigate to the current page is not trigger OnInitializedAsync, equivalent to js pushState (), but there is no matching function
 
[Inject]
Private NavigationManager Navigation {get; The set; }

Private asycn Task QueryAsycn ()
{

/* if I is the current page/Demo
* so I want to filter data, navigate to/Demo? Name=123, the address will change, but not OnInitializedAsync
* don't know is I didn't keep up with the idea of or should have been like this
*/
Navigation. NavigateTo ("/Demo? Name=123 ");
//if you navigate to another page is in line with expectations, such as
Navigation. NavigateTo ("/Welcome? Name=123 ");

//so I currently processing way is navigateTo, continue to query data update UI
Source=await LoadDataAsync ();
}


RenderFragment code way to build good trouble, I development way is
Welcome. Razor
Cs
Welcome. The razor.
 
//file Welcome. Razor. Cs
Public partial class Webcome {}

After thinking of good maintenance, see clearly, more pure and clean, but had to is added on the razor code
 
//on the razor files build RenderFragment is very simple, var rf=@ & lt; Tag>
Private string NewTag {get; The set; }

Private RenderFragment DropdownRender (RenderFragment originNode)
{
RenderFragment customDropdownRender=
@ & lt; Template>

@ originNode



;

Return customDropdownRender;
}

Private void AddItem (MouseEventArgs args)
{
if (! String. IsNullOrWhiteSpace (NewTag))
{
_tags. AddItem (NewTag);
NewTag=string. The Empty;
}
}

//but in cs file build very troublesome, RenderFragment is a tree structure, just a simple ICONS are not so convenient
Var (=builder=& gt;
{
Builder. OpenComponent (0);
Builder. AddAttribute (0, "Type", "the exclamation - circle");
Builder. AddAttribute (1, "Theme", "outline");
Builder. CloseComponent ();
},


As far as I'm the example above, just for new a value in the drop-down box pit me miserable, it took me half a day, just in order to realize such a function

Then an error

Because of what? Because NewTag in the beginning I define fields, not an attribute
Private string _newTag=string. The Empty;
Take half a day time wasted here,

There is a routing problem, because I have to manage some files, so the routing parameter values must be inside (. Dot points) this symbol, then 404,
Well, thought for a moment, must be as a static file access to treatment, no problem,
Then I go to the MSDN find documents to see what is the solution
Just have,
The
reference
Routing with URLs that contain dots
For hosted Blazor WebAssembly and Blazor Server apps, the server-side default route template assumes that if the last segment of a request URL contains a dot (.) that a file is requested. For example, the URL https://localhost.com:5001/example/some.thing is interpreted by the router as a request for a file named some.thing. Without additional configuration, an app returns a 404 - Not Found response if some.thing was meant to route to a component with an @page directive and some.thing is a route parameter value. To use a route with one or more parameters that contain a dot, the app must configure the route with a custom template.

Consider the following Example component that can receive a route parameter from the last segment of the URL.
 
@ page "/example/{param? }
"


Param: @ Param



@ code {
[Parameter]
Public string Param {get; The set; }
}

Do, then happy, still 404
There is no solution, ha ha, later still not solve, I will adopt the way of the QueryString,





Ha ha ha ha, wrote a few days, want to fun fun fun fun

CodePudding user response:

Exception handling is bad lines, it is easy to hang line hang up you have to refresh the restart line

Other is good, a most pit was his life cycle is based on the connection, that you rely on injection of service by default as a singleton scope equivalent, pit!!!! If you use EF things put you deep pit now, this website must drop pit
  •  Tags:  
  • C#
  • Related