1 | initial version |
In Vite, you can add the base URL to the 404.html file by including the following code at the top of the file:
<script>
const baseUrl = import.meta.env.BASE_URL;
const url = new URL(window.location.href);
url.pathname = baseUrl + '/404.html';
window.location = url.href;
</script>
This code gets the current base URL from the Vite environment variable import.meta.env.BASE_URL
, then modifies the current URL and redirects the user to the 404 page with the updated base URL.