Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function Router(props) {
const [currentPath, setCurrentPath] = useState('');
// return initial component in ssr
if (isNode && routerConfig.InitialComponent) {
return createElement(routerConfig.InitialComponent, props);
}
const { component } = RaxUseRouter.useRouter(() => _routerConfig);
if (!component || Array.isArray(component) && component.length === 0) {
// Return null directly if not matched.
return null;
} else {
// process Page.getInitialProps
if (isWeb && _currentPagePath !== _history.location.pathname) {
_initialProps = {};
_currentPagePath = _history.location.pathname;
// SSR project the first time is initialized from global data,
// after that the data will be obtained from the component's own getInitialProps
if (_initialPropsFromSSR !== null && !_isReadInitialPropsFromSSR) {
// After routing switching, it is considered not the first rendering.
_initialProps = _initialPropsFromSSR;
_isReadInitialPropsFromSSR = true;
} else if (component.getInitialProps) {
function Entry(props) {
const { history } = props;
const { component } = useRouter(() => props);
// For async getInitialProps method update Entry component.
const [tempPath, setTempPath] = useState('');
if (!component || Array.isArray(component) && component.length === 0) {
// Return null directly if not matched.
return null;
} else {
// TODO new SSR app.js
if (component.getInitialProps && currentPagePath !== history.location.pathname) {
pageInitialProps = {};
currentPagePath = history.location.pathname;
component.getInitialProps().then((props) => {
pageInitialProps = props;
setTempPath(currentPagePath);
}).catch(() => {
function Entry(props) {
const { component } = useRouter(() => props);
if (!component || Array.isArray(component) && component.length === 0) {
// Return null directly if not matched.
return null;
} else {
return createElement(component, { ...props });
}
}
function App(props) {
const { appConfig, history, routes, InitialComponent } = props;
const { component } = useRouter(() => ({ history, routes, InitialComponent }));
if (isNullableComponent(component)) {
// Return null directly if not matched.
return null;
} else {
const [pageInitialProps, setPageInitialProps] = useState(
// If SSR is enabled, set pageInitialProps: {pagePath: pageData}
initialDataFromSSR ? { [initialDataFromSSR.pagePath || '']: initialDataFromSSR.pageData || {} } : {}
);
// If SSR is enabled, process getInitialProps method
if (isWeb && initialDataFromSSR && component.getInitialProps && !pageInitialProps[component.__path]) {
useEffect(() => {
const getInitialPropsPromise = component.getInitialProps();
// Check getInitialProps returns promise.
return function(props) {
routerProps = { ...props, router };
if (InitialComponent) {
routerConfig.InitialComponent = ;
}
const { component } = useRouter(routerConfig);
const [updateTemp, setUpdateTemp] = useState(null);
updateComponentTrigger = setUpdateTemp;
if (!withPageAlive) {
return component;
} else {
let cachePageMatched = false;
return (
<div style="{{">
{Object.keys(alivePageCache).map((pageName) => {
cachePageMatched = isPathMatched(withSSR ? 'history' : 'hash', alivePageCache[pageName].regexp, pageName);
const element = alivePageCache[pageName].component;
if (cachePageMatched && element === null) {
activateAlivePageComponent(pageName);
}
if (cachePageMatched && alivePageCache[pageName].title) {</div>