/
entry-point.js
68 lines (62 loc) 路 2.26 KB
/
entry-point.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import React from 'react';
import {
ApplicationShell,
setupGlobalErrorListener,
RouteCatchAll,
} from '@commercetools-frontend/application-shell';
import { Sdk } from '@commercetools-frontend/sdk';
import * as globalActions from '@commercetools-frontend/actions-global';
import { Redirect, Route, Switch } from 'react-router-dom';
const loadApplicationMessagesForLanguage = async lang => {
const messages = await import(`../../i18n/data/${lang}.json` /* webpackChunkName: "application-messages-[request]" */);
return messages.default;
};
// Here we split up the main (app) bundle with the actual application business logic.
// Splitting by route is usually recommended and you can potentially have a splitting
// point for each route. More info at https://reactjs.org/docs/code-splitting.html
const AsyncApplicationRoutes = React.lazy(() =>
import('../../routes' /* webpackChunkName: "starter-routes" */)
);
export const ApplicationStarter = () => (
<Switch>
{/* For development, it's useful to redirect to the actual
application routes when you open the browser at http://localhost:3001 */
process.env.NODE_ENV === 'production' ? null : (
<Redirect
exact={true}
from="/:projectKey"
to="/:projectKey/examples-starter"
/>
)}
<Route
path="/:projectKey/examples-starter"
component={AsyncApplicationRoutes}
/>
{/* Catch-all route */}
<RouteCatchAll />
</Switch>
);
ApplicationStarter.displayName = 'ApplicationStarter';
// Ensure to setup the global error listener before any React component renders
// in order to catch possible errors on rendering/mounting.
setupGlobalErrorListener();
class EntryPoint extends React.Component {
static displayName = 'EntryPoint';
render() {
return (
<ApplicationShell
environment={window.app}
onRegisterErrorListeners={({ dispatch }) => {
Sdk.Get.errorHandler = error =>
globalActions.handleActionError(error, 'sdk')(dispatch);
}}
applicationMessages={loadApplicationMessagesForLanguage}
DEV_ONLY__loadNavbarMenuConfig={() =>
import('../../../menu.json').then(data => data.default || data)
}
render={() => <ApplicationStarter />}
/>
);
}
}
export default EntryPoint;