SubDomain için ayrı Layout
This commit is contained in:
parent
64ccc150df
commit
91be964a39
5 changed files with 49 additions and 32 deletions
|
|
@ -14,6 +14,7 @@ import useDirection from '@/utils/hooks/useDirection'
|
|||
import useLocale from '@/utils/hooks/useLocale'
|
||||
import { useDynamicRoutes } from '@/routes/dynamicRoutesContext'
|
||||
import { useLocation } from 'react-router-dom'
|
||||
import { hasSubdomain } from '@/utils/subdomain'
|
||||
|
||||
export type LayoutType =
|
||||
| typeof LAYOUT_TYPE_CLASSIC
|
||||
|
|
@ -65,7 +66,7 @@ const Layout = () => {
|
|||
return layouts[layoutType]
|
||||
}
|
||||
|
||||
if (route?.routeType === 'authenticated') {
|
||||
if (route?.routeType === 'authenticated' || hasSubdomain()) {
|
||||
return AuthLayout
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,31 +64,31 @@ const PublicLayout = () => {
|
|||
{
|
||||
resourceKey: 'Public.nav.home',
|
||||
name: translate('::Public.nav.home'),
|
||||
path: '/home',
|
||||
path: ROUTES_ENUM.public.home,
|
||||
icon: Home,
|
||||
},
|
||||
{
|
||||
resourceKey: 'Public.nav.about',
|
||||
name: translate('::Public.nav.about'),
|
||||
path: '/about',
|
||||
path: ROUTES_ENUM.public.about,
|
||||
icon: Info,
|
||||
},
|
||||
{
|
||||
resourceKey: 'Public.nav.services',
|
||||
name: translate('::Public.nav.services'),
|
||||
path: '/services',
|
||||
path: ROUTES_ENUM.public.services,
|
||||
icon: Briefcase,
|
||||
},
|
||||
{
|
||||
resourceKey: 'Public.nav.products',
|
||||
name: translate('::Public.nav.products'),
|
||||
path: '/products',
|
||||
path: ROUTES_ENUM.public.products,
|
||||
icon: Package,
|
||||
},
|
||||
{
|
||||
resourceKey: 'Public.nav.blog',
|
||||
name: translate('::Public.nav.blog'),
|
||||
path: '/blog',
|
||||
path: ROUTES_ENUM.public.blog,
|
||||
icon: BookOpen,
|
||||
},
|
||||
{
|
||||
|
|
@ -100,10 +100,14 @@ const PublicLayout = () => {
|
|||
{
|
||||
resourceKey: 'Public.nav.contact',
|
||||
name: translate('::Public.nav.contact'),
|
||||
path: '/contact',
|
||||
path: ROUTES_ENUM.public.contact,
|
||||
icon: Phone,
|
||||
},
|
||||
{ resourceKey: 'Public.nav.giris', name: translate('::Public.nav.giris'), path: '/login' },
|
||||
{
|
||||
resourceKey: 'Public.nav.giris',
|
||||
name: translate('::Public.nav.giris'),
|
||||
path: ROUTES_ENUM.authenticated.login,
|
||||
},
|
||||
]
|
||||
|
||||
const getNavItemClass = (resourceKey?: string) => {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import ProtectedRoute from '@/components/route/ProtectedRoute'
|
|||
import PermissionGuard from '@/components/route/PermissionGuard'
|
||||
import PageContainer from '@/components/template/PageContainer'
|
||||
import { ROUTES_ENUM } from './route.constant'
|
||||
import { hasSubdomain } from '@/utils/subdomain'
|
||||
|
||||
export const DynamicRouter: React.FC = () => {
|
||||
const { routes, loading, error } = useDynamicRoutes()
|
||||
|
|
@ -18,7 +19,6 @@ export const DynamicRouter: React.FC = () => {
|
|||
|
||||
return (
|
||||
<Routes>
|
||||
{/* Protected Admin Routes */}
|
||||
<Route path="/admin/*" element={<ProtectedRoute />}>
|
||||
{dynamicRoutes
|
||||
.filter((r) => r.routeType === 'protected')
|
||||
|
|
@ -40,11 +40,9 @@ export const DynamicRouter: React.FC = () => {
|
|||
/>
|
||||
)
|
||||
})}
|
||||
{/* /admin -> /admin/home yönlendirmesi */}
|
||||
<Route index element={<Navigate to={ROUTES_ENUM.protected.dashboard} replace />} />
|
||||
</Route>
|
||||
|
||||
{/* Public Routes (dinamik) */}
|
||||
{dynamicRoutes
|
||||
.filter((r) => r.routeType !== 'protected')
|
||||
.map((route) => {
|
||||
|
|
@ -62,9 +60,16 @@ export const DynamicRouter: React.FC = () => {
|
|||
)
|
||||
})}
|
||||
|
||||
{/* / yönlendirmesi → /home */}
|
||||
<Route path="/" element={<Navigate to="/home" replace />} />
|
||||
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<Navigate
|
||||
to={hasSubdomain() ? ROUTES_ENUM.authenticated.login : ROUTES_ENUM.public.home}
|
||||
replace
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Not Found */}
|
||||
<Route path="*" element={<NotFound />} />
|
||||
</Routes>
|
||||
|
|
|
|||
24
ui/src/utils/subdomain.ts
Normal file
24
ui/src/utils/subdomain.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
const defaultSubDomain = 'KURS'
|
||||
|
||||
export const getSubdomain = (): string | null => {
|
||||
if (typeof window === 'undefined') return null
|
||||
|
||||
const hostname = window.location.hostname
|
||||
const parts = hostname.split('.')
|
||||
|
||||
// localhost veya normal domain ise subdomain yok
|
||||
if (hostname === 'localhost' || parts.length < 3) {
|
||||
return null
|
||||
}
|
||||
|
||||
// Default subdomain ise null döndür
|
||||
if (parts[0].toUpperCase() === defaultSubDomain) {
|
||||
return null
|
||||
}
|
||||
|
||||
return parts[0].toUpperCase()
|
||||
}
|
||||
|
||||
export const hasSubdomain = (): boolean => {
|
||||
return getSubdomain() !== null
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ import { motion } from 'framer-motion'
|
|||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import * as Yup from 'yup'
|
||||
import { getSubdomain } from '@/utils/subdomain'
|
||||
|
||||
type SignInFormSchema = {
|
||||
userName: string
|
||||
|
|
@ -67,24 +68,6 @@ const Login = () => {
|
|||
|
||||
const defaultSubDomain = 'KURS'
|
||||
|
||||
const getSubdomain = () => {
|
||||
if (typeof window === 'undefined') return null
|
||||
|
||||
const hostname = window.location.hostname
|
||||
|
||||
const parts = hostname.split('.')
|
||||
|
||||
if (hostname === 'localhost' || parts.length < 3) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (parts[0].toUpperCase() === defaultSubDomain) {
|
||||
return null
|
||||
}
|
||||
|
||||
return parts[0].toUpperCase()
|
||||
}
|
||||
|
||||
const onSignIn = async (
|
||||
values: SignInFormSchema,
|
||||
{ setSubmitting, isSubmitting, setFieldValue, setFieldTouched }: any,
|
||||
|
|
|
|||
Loading…
Reference in a new issue