Skip to content

Commit 9d74f33

Browse files
committed
Force a full reload when a ?anchor ends up in the not found to get netlify redirects. This is an issue when links within the app still reference ?anchor (perhaps from markdown). Our alternatives are to return to ?anchor or to add support to redirecting to #anchors to the Ember Router.
1 parent 9761236 commit 9d74f33

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

app/routes/not-found.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,23 @@ export default class NotFoundRoute extends Route {
1111

1212
this.fastboot.response.statusCode = 404;
1313
}
14+
15+
redirect() {
16+
if (typeof window === 'undefined' || !window.location) {
17+
return;
18+
}
19+
const url = new URL(window.location.href);
20+
const anchor = url.searchParams.get('anchor');
21+
const redirected = url.searchParams.get('redirected');
22+
if (anchor && !redirected) {
23+
url.searchParams.set('redirected', '1');
24+
// If we get here with an anchor query param, it means something in the
25+
// api docs app is continuing to link to it (sometimes in the markdown)
26+
// Force full reload to get netlify redirects
27+
window.location.replace(url.toString());
28+
// A more elegant solution would be to restore the various routes that
29+
// handled ?anchor previously and redirect from there but that would
30+
// necessitate adding support to the Ember Router to redirect to #anchors
31+
}
32+
}
1433
}

0 commit comments

Comments
 (0)