@@ -132,10 +132,10 @@ function onDocumentSubmit(event: SubmitEvent) {
132132
133133 event . preventDefault ( ) ;
134134
135- const url = new URL ( event . submitter ?. getAttribute ( 'formaction' ) || formElem . action , document . baseURI ) ;
136- const fetchOptions : RequestInit = { method : method } ;
135+ const url = new URL ( event . submitter ?. getAttribute ( 'formaction' ) || formElem . action , document . baseURI ) ;
136+ const fetchOptions : RequestInit = { method : method } ;
137137 const formData = new FormData ( formElem ) ;
138-
138+
139139 const submitterName = event . submitter ?. getAttribute ( 'name' ) ;
140140 const submitterValue = event . submitter ! . getAttribute ( 'value' ) ;
141141 if ( submitterName && submitterValue ) {
@@ -153,8 +153,8 @@ function onDocumentSubmit(event: SubmitEvent) {
153153 } else {
154154 // Setting request body and content-type header depending on enctype
155155 const enctype = event . submitter ?. getAttribute ( 'formenctype' ) || formElem . enctype ;
156- if ( enctype === 'multipart/form-data' ) {
157- // Content-Type header will be set to 'multipart/form-data'
156+ if ( enctype === 'multipart/form-data' ) {
157+ // Content-Type header will be set to 'multipart/form-data'
158158 fetchOptions . body = formData ;
159159 } else {
160160 fetchOptions . body = urlSearchParams ;
@@ -170,7 +170,7 @@ function onDocumentSubmit(event: SubmitEvent) {
170170 }
171171}
172172
173- export async function performEnhancedPageLoad ( internalDestinationHref : string , interceptedLink : boolean , fetchOptions ?: RequestInit ) {
173+ export async function performEnhancedPageLoad ( internalDestinationHref : string , interceptedLink : boolean , fetchOptions ?: RequestInit , treatAsRedirectionFromMethod ?: 'get' | 'post' ) {
174174 performingEnhancedPageLoad = true ;
175175
176176 // First, stop any preceding enhanced page load
@@ -232,8 +232,9 @@ export async function performEnhancedPageLoad(internalDestinationHref: string, i
232232 // For 301/302/etc redirections to internal URLs, the browser will already have followed the chain of redirections
233233 // to the end, and given us the final content. We do still need to update the current URL to match the final location,
234234 // then let the rest of enhanced nav logic run to patch the new content into the DOM.
235- if ( response . redirected ) {
236- if ( isGetRequest ) {
235+ if ( response . redirected || treatAsRedirectionFromMethod ) {
236+ const treatAsGet = treatAsRedirectionFromMethod ? ( treatAsRedirectionFromMethod === 'get' ) : isGetRequest ;
237+ if ( treatAsGet ) {
237238 // For gets, the intermediate (redirecting) URL is already in the address bar, so we have to use 'replace'
238239 // so that 'back' would go to the page before the redirection
239240 history . replaceState ( null , '' , response . url ) ;
0 commit comments