Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aio/content/guide/service-worker-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ This optional section enables you to specify a custom list of URLs that will be
The ServiceWorker redirects navigation requests that don't match any `asset` or `data` group to the specified [index file](#index-file).
A request is considered to be a navigation request if:

* Its [method](https://developer.mozilla.org/docs/Web/API/Request/method) is `GET`
* Its [mode](https://developer.mozilla.org/docs/Web/API/Request/mode) is `navigation`
* It accepts a `text/html` response as determined by the value of the `Accept` header
* Its URL matches the following criteria:
Expand Down
4 changes: 2 additions & 2 deletions packages/service-worker/worker/src/app-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ export class AppVersion implements UpdateSource {

/**
* Determine whether the request is a navigation request.
* Takes into account: Request mode, `Accept` header, `navigationUrls` patterns.
* Takes into account: Request method and mode, `Accept` header, `navigationUrls` patterns.
*/
isNavigationRequest(req: Request): boolean {
if (req.mode !== 'navigate') {
if (req.method !== 'GET' || req.mode !== 'navigate') {
return false;
}

Expand Down
8 changes: 8 additions & 0 deletions packages/service-worker/worker/test/happy_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,14 @@ describe('Driver', () => {
server.assertNoOtherRequests();
});

it('does not redirect to index on a non-GET request', async () => {
expect(await navRequest('/baz', {method: 'POST'})).toBeNull();
server.assertSawRequestFor('/baz');

expect(await navRequest('/qux', {method: 'PUT'})).toBeNull();
server.assertSawRequestFor('/qux');
});

it('does not redirect to index on a non-navigation request', async () => {
expect(await navRequest('/baz', {mode: undefined})).toBeNull();
server.assertSawRequestFor('/baz');
Expand Down