fix redirect for static export in semi spa mode

This commit is contained in:
Michael Schramm 2020-06-02 00:51:17 +02:00
parent 472e07bd29
commit c1ba7f2556
2 changed files with 32 additions and 9 deletions

View File

@ -6,6 +6,7 @@ import 'assets/global.scss'
import 'assets/variables.scss'
import axios from 'axios'
import {authConfig} from 'components/with.auth'
import 'i18n'
import {AppProps} from 'next/app'
import getConfig from 'next/config'
import Head from 'next/head'
@ -34,11 +35,4 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
)
}
const WrappedApp = wrapper.withRedux(App)
WrappedApp.getInitialProps = async (): Promise<any> => {
// important for now to pass public runtime config to clients!
return {}
}
export default WrappedApp
export default wrapper.withRedux(App)

View File

@ -1,9 +1,38 @@
import {Layout} from 'antd'
import {AuthFooter} from 'components/auth/footer'
import {NextPage} from 'next'
import React from 'react'
import {useRouter} from 'next/router'
import React, {useEffect} from 'react'
import {LoadingPage} from '../components/loading.page'
const Index: NextPage = () => {
const router = useRouter()
useEffect(() => {
if (router.pathname !== window.location.pathname) {
let href = router.asPath
let as = router.asPath;
[
/(\/form\/)[^\/]+/i,
/(\/admin\/forms\/)[^\/]+/i,
/(\/admin\/users\/)[^\/]+/i,
].forEach(r => {
if (r.test(as)) {
href = href.replace(r, '$1[id]')
}
})
router.replace(href, as)
}
})
if (process.browser && router.pathname !== window.location.pathname) {
return (
<LoadingPage message={'redirecting'} />
)
}
return (
<Layout style={{
height: '100vh',