Skip to content

Instantly share code, notes, and snippets.

@dirumahrafif
Last active May 15, 2024 18:47
Show Gist options
  • Save dirumahrafif/2bfa4dcc1f6a2e42cd1aa2ac046b5dba to your computer and use it in GitHub Desktop.
Save dirumahrafif/2bfa4dcc1f6a2e42cd1aa2ac046b5dba to your computer and use it in GitHub Desktop.
Deploy React js Application to subdirectory using vite
  • perbaiki di file App.jsx / yang mengandung BrowserRouter
function App() {
  return (
    <BrowserRouter basename="/nama-direktori">
      {/* lokasi router */}
    </BrowserRouter>
  );
}
  • Perbaiki di bagian file vite.config.js
export default defineConfig({
  plugins: [react()],
  base: '/nama-direktori/',
});
  • Jalankan proses build
npm run build
  • Masukkan dalam file .htaccess
RewriteEngine On
RewriteBase /nama-direktori/
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /nama-direktori/index.html [L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment