Allow configuration from root URL path

This commit is contained in:
Corné Dorrestijn 2022-12-29 17:42:54 +01:00
parent 2495dd2b9e
commit 41b3d409fd
No known key found for this signature in database
GPG key ID: E01A9819F86CE169
2 changed files with 10 additions and 2 deletions

View file

@ -2,7 +2,7 @@ import React from 'react';
import { Switch, Route, Redirect } from 'react-router-dom'; import { Switch, Route, Redirect } from 'react-router-dom';
import LandingGradient from 'soapbox/components/landing-gradient'; import LandingGradient from 'soapbox/components/landing-gradient';
import { useAppSelector } from 'soapbox/hooks'; import { useAppSelector, useSoapboxConfig } from 'soapbox/hooks';
import { isStandalone } from 'soapbox/utils/state'; import { isStandalone } from 'soapbox/utils/state';
import AboutPage from '../about'; import AboutPage from '../about';
@ -13,6 +13,9 @@ import Header from './components/header';
const PublicLayout = () => { const PublicLayout = () => {
const standalone = useAppSelector((state) => isStandalone(state)); const standalone = useAppSelector((state) => isStandalone(state));
const soapboxConfig = useSoapboxConfig();
const shouldRedirectFromRoot = soapboxConfig.redirectRootNoLogin && !soapboxConfig.redirectRootNoLogin.match(/^\/?$/);
if (standalone) { if (standalone) {
return <Redirect to='/login/external' />; return <Redirect to='/login/external' />;
@ -28,7 +31,11 @@ const PublicLayout = () => {
<div className='relative'> <div className='relative'>
<Switch> <Switch>
<Route exact path='/' component={LandingPage} /> {shouldRedirectFromRoot ? (
<Redirect exact path='/' to={soapboxConfig.redirectRootNoLogin} />
) : (
<Route exact path='/' component={LandingPage} />
)}
<Route exact path='/about/:slug?' component={AboutPage} /> <Route exact path='/about/:slug?' component={AboutPage} />
</Switch> </Switch>
</div> </div>

View file

@ -115,6 +115,7 @@ export const SoapboxConfigRecord = ImmutableRecord({
feedInjection: true, feedInjection: true,
tileServer: '', tileServer: '',
tileServerAttribution: '', tileServerAttribution: '',
redirectRootNoLogin: '/',
}, 'SoapboxConfig'); }, 'SoapboxConfig');
type SoapboxConfigMap = ImmutableMap<string, any>; type SoapboxConfigMap = ImmutableMap<string, any>;