fix(store): ensure trailing slash on storefront routing and redirect /store to prevent blank page on reload (#83) #95

Merged
amit merged 1 commits from issue-83 into main 2026-11-12 04:39:03 +00:00
2 changed files with 35 additions and 6 deletions

View File

@ -36,8 +36,8 @@ export default function App() {
setActiveTab(tab);
if (typeof window !== 'undefined') {
const isStorePrefix = window.location.pathname.startsWith('/store');
const basePath = isStorePrefix ? '/store' : '';
const newPath = tab === 'storefront' ? (basePath || '/') : (basePath + '/' + tab);
const basePath = isStorePrefix ? '/store/' : '/';
const newPath = tab === 'storefront' ? basePath : `${basePath}${tab}`;
if (window.location.pathname !== newPath) {
window.history.pushState({ tab }, '', newPath);
}
@ -235,6 +235,12 @@ export default function App() {
// Load configuration & user profile on startup
useEffect(() => {
// Normalize URL if opened at /store without trailing slash
if (typeof window !== 'undefined' && window.location.pathname === '/store') {
const normalizedPath = '/store/' + (window.location.search || '') + (window.location.hash || '');
window.history.replaceState(window.history.state, document.title, normalizedPath);
}
const params = new URLSearchParams(window.location.search);
const urlToken = params.get('token');
const urlPlanCode = params.get('planCode');
@ -269,8 +275,10 @@ export default function App() {
}
if (urlToken || urlPlanCode) {
const newUrl = window.location.pathname;
window.history.replaceState({}, document.title, newUrl);
const isStorePrefix = window.location.pathname.startsWith('/store');
const basePath = isStorePrefix ? '/store/' : '/';
const cleanPath = activeTab === 'subscriptions' ? `${basePath}subscriptions` : basePath;
window.history.replaceState({}, document.title, cleanPath);
}
// Fetch public Razorpay Config

View File

@ -1,11 +1,32 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
const rawBase = process.env.VITE_BASE_PATH || '/store/'
const baseWithoutSlash = rawBase.endsWith('/') ? rawBase.slice(0, -1) : rawBase
// https://vite.dev/config/
export default defineConfig({
base: process.env.VITE_BASE_PATH || '/store/',
plugins: [react()],
base: rawBase,
plugins: [
react(),
{
name: 'redirect-base-middleware',
configureServer(server) {
server.middlewares.use((req, res, next) => {
const [pathname, search] = (req.url || '').split('?')
if (baseWithoutSlash && pathname === baseWithoutSlash) {
const target = `${rawBase}${search ? `?${search}` : ''}`
res.writeHead(302, { Location: target })
res.end()
return
}
next()
})
}
}
],
server: {
port: 3000,
}
})