Skip to content

Commit 2855078

Browse files
ReactReduxSpa's boot-server now supports redirections issued by react-router
1 parent 1be9102 commit 2855078

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

templates/ReactReduxSpa/ClientApp/boot-server.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@ import { match, RouterContext } from 'react-router';
55
import createMemoryHistory from 'history/lib/createMemoryHistory';
66
import routes from './routes';
77
import configureStore from './configureStore';
8+
type BootResult = { html?: string, globals?: { [key: string]: any }, redirectUrl?: string};
89

910
export default function (params: any): Promise<{ html: string }> {
10-
return new Promise<{ html: string, globals: { [key: string]: any } }>((resolve, reject) => {
11+
return new Promise<BootResult>((resolve, reject) => {
1112
// Match the incoming request against the list of client-side routes
1213
match({ routes, location: params.location }, (error, redirectLocation, renderProps: any) => {
1314
if (error) {
1415
throw error;
1516
}
1617

18+
// If there's a redirection, just send this information back to the host application
19+
if (redirectLocation) {
20+
resolve({ redirectUrl: redirectLocation.pathname });
21+
return;
22+
}
23+
1724
// If it didn't match any route, renderProps will be undefined
1825
if (!renderProps) {
1926
throw new Error(`The location '${ params.url }' doesn't match any route configured in react-router.`);

0 commit comments

Comments
 (0)