Skip to content

Commit 840a185

Browse files
committed
feat: add config option to use the react-router HashRouter
1 parent 5f5b98f commit 840a185

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/framework/client/_react-router.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @flow
2+
3+
// this module is ran on node before webpack bundles it.
4+
5+
/* eslint-disable import/no-commonjs */
6+
7+
// need to import from /lib (the version in which webpack is running) otherwise it will use /es
8+
const config = require('../../../lib/shared/framework-config');
9+
10+
module.exports = function getRouteDeclarations() {
11+
12+
const routerKey = config.default.routingType === 'hash' ? 'HashRouter' : 'BrowserRouter';
13+
14+
return {
15+
code: `
16+
export { ${routerKey} as Router } from 'react-router-dom';
17+
`,
18+
};
19+
};

src/framework/client/init-render.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1+
// @flow
2+
13
import React from 'react';
24
import ReactDOM from 'react-dom';
3-
import { createBrowserHistory } from 'history';
4-
import { Router } from 'react-router-dom';
55
import { CookiesProvider } from 'react-cookie';
66
import serverStyleCleanup from 'node-style-loader/clientCleanup';
77
import { loadableReady } from '@loadable/component';
8+
import { Router } from 'val-loader!./_react-router';
89
import { getDefault } from '../../shared/util/ModuleUtil';
910
import ReworkRootComponent from '../app/ReworkRootComponent';
1011
import { rootRoute } from '../common/kernel';
1112
import BrowserLanguageProvider from './browser-language-provider';
1213
import ClientHooks from './client-hooks';
1314

14-
// TODO: support hashHistory somehow (cli option ?)
15-
1615
let rootComponent = (
1716
<BrowserLanguageProvider>
1817
<CookiesProvider>
1918
<ReworkRootComponent>
20-
<Router history={createBrowserHistory()}>
19+
<Router>
2120
{rootRoute}
2221
</Router>
2322
</ReworkRootComponent>

src/shared/framework-config/framework-config-type.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export type FrameworkPluginConfig = {
55
};
66

77
export type FrameworkConfigStruct = {
8+
9+
routingType: 'browser' | 'hash',
10+
811
directories: {
912
logs: string,
1013
build: string,

src/shared/framework-config/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function getUserConfig() {
4040

4141
function normalizeConfig(config: Object) {
4242
const schema = Joi.object().keys({
43+
routingType: Joi.string().valid(['browser', 'hash']).default('browser'),
4344
routes: Joi.string().default('src/**/*.route.js'),
4445
'entry-react': Joi.string().allow(null).default(null),
4546
'render-html': Joi.string().allow(null).default(null),

0 commit comments

Comments
 (0)