I managed it by adding this conditional:
if (performance.navigation.type >= 0) {
api.previewer.previewUrl.set(api.settings.url.home + '?page_id=' + pageID);
}
This takes care of all the navigation possibilities. It’s sort of a workaround but it does the trick.
MDN Web Doc: