How can I update the URL to reflect state in a single page web app?

So I'm trying to figure out an approach to a broad problem (that I expect is too broad for SO). I have a single page web application (well two, actually) that consists of a JS frontend that takes some text parameters, sends them to a C# Web API, and produces some sort of dynamically generated visual from the response. In both cases, I would like to be able to produce links that refer directly to the search results, rather than saying "go to www.mypage.com and enter myParameter in the parameter1 box, etc."

I understand this is fairly common practice, but I don't really know what it's called or where to start.

The approach that I can think of is configuring the MyPageController that returns the view that I use for my single page app to accept parameters in a GET request querystring, call the API methods directly on the server (rather than via HTTP from the client) and then return this data with the View. This seems at least approachable, but it doesn't allow me to dynamically update the URL with state so users could just paste a URL and send it to someone to see their results. It would also require a lot more rewritten logic than a client-side solution.

Is this the right approach? Is it possible to do all this on the client-side instead? Doing so would definitely fit more seamlessly into my existing logic (I'd get to be lazier and update less), but I haven't found much in terms of JS libraries to accomplish this from cursory searching, so I'm presuming it's bad practice.

by ItWasTheMiddleOne via /r/csharp

Leave a Reply