Let's say I have a CRUD controller on the server side that follows the well-known
Post/Redirect/Get pattern. There's a details endpoint at /details/ID
that returns a details page for the object at ID; it answers to GET.
There's an edit endpoint at /edit/ID; on GET it returns a form view;, on
POST it redirects to the details endpoint.
Now say I want to have a page that switches between the details view and
edit view; the details view has an edit link with an ic-get-from on it
going to the edit endpoint. The edit view's form element has an
ic-post-to the same location the form normally posts to (the edit
endpoint). Both intercooler actions have ic-push-url set to true, and
ic-hist-elt is set on the main container on the page.
At this point, everything works correctly *except* for the URL. The
ic-get-from to swap in the edit view from the details view works fine.
But once you are on the edit page, submitting the form pushes the URL of
the edit endpoint, not the URL of the details endpoint, even though
visually you are now on the details page. I assume this is because the
intercooler request is actually to the edit endpoint. With this basic
(and common, IMO) setup, how can I get the URL of the details endpoint
into the URL bar and the history?
Answer (which I realized while writing out the question in sufficient
detail):
The details endpoint should check its request headers for the presence
of X-IC-Request. If true, then it should set the X-IC-PushURL header on
its response. It can't check its form values or GET query string for
ic-request, because it won't have any; it must check for the
X-IC-Request header.
--
Jason McBrayer | “Strange is the night where black stars rise,
jmc...@carcosa.net | and strange moons circle through the skies,
| but stranger still is lost Carcosa.”
| ― Robert W. Chambers,The King in Yellow