I have a URL /books
, which lists some books, and a URL pattern /books/{some-book-title}
which shows a view/update form for the metadata of a book. Here's a typical user story, where a user corrects an incorrect author entry:
GET /books
<a href="/books/ulysses">Ulysses</a>
<a href="/books/don-quixote">Don Quixote</a>
GET /books/ulysses
<form action="/books/ulysses" method="post" enctype="application/x-www-form-urlencoded">
<input name="author" value="Jamessss Joycessss">
</form>
POST /books/ulysses FORMDATA author=James+Joyce
Redirect 303 SEE OTHER location = /books/ulysses
GET /books/ulysses
<form action="/books/ulysses" method="post" enctype="application/x-www-form-urlencoded">
<input name="author" value="James Joyce">
</form>
The problem is that the history stack is now
/books
/books/ulysses
/books/ulysses
so that when the user presses "back", they don't go back to /books
, they just refresh the current page. Is there a non-javascript way to handle the update case so that the back button has the expected behavior? And if not, what's the javascript way to fix this?
EDIT: even more confusing if you post multiple times
GET /books
GET /books/ulysses author=Jamesss Joycesss
POST author=3 -> redirect shows author=3
POST author=2 -> redirect shows author=2
POST author=1 -> redirect shows author=1
Press back button /books/ulysses shows author=1
Press back button /books/ulysses shows author=2 (!!!)
Press back button /books/ulysses shows author=3 (!!!)
Press back button /books