Commit 2a5c6817 authored by Matija Obreza's avatar Matija Obreza
Browse files

Fix: SSR for top-level navigation

- location is a reserved word, doesn't trigger compile-time error if not provided
parent ea2c1e2f
import * as React from 'react';
import { connect } from 'react-redux';
import { translate } from 'react-i18next';
import renderRoutes from 'ui/renderRoutes';
......@@ -63,4 +64,9 @@ const Layout = ({route, match, t, location}: { route: any, match: any, t: any, l
</div>
);
export default translate()(Layout);
const mapStateToProps = (state, ownProps) => ({
location: ownProps.location,
});
export default translate()(connect(mapStateToProps)(Layout));
......@@ -26,7 +26,7 @@ interface IMenuBarProps extends React.ClassAttributes<any> {
class MenuBar extends React.Component<IMenuBarProps, any> {
private renderMenu = (path: any) => {
const { t } = this.props;
const { t, location } = this.props;
return (
path.subMenus ? (
<MenuItem
......@@ -48,7 +48,7 @@ class MenuBar extends React.Component<IMenuBarProps, any> {
}
private renderSubMenu = (path: any) => {
const {t} = this.props;
const { t, location } = this.props;
return (
<MenuItem
label={ t(path.label) }
......@@ -60,8 +60,8 @@ class MenuBar extends React.Component<IMenuBarProps, any> {
}
public render() {
const {classes, location, menuItems} = this.props;
console.log(location.pathname);
const { classes, location, menuItems } = this.props;
console.log(`Rendering menues with current location=${location.pathname}`);
return (
<nav className={ classes.nav }>
{ menuItems.map(this.renderMenu) }
......
......@@ -149,7 +149,7 @@ interface IHeaderProps extends React.ClassAttributes<any> {
classes?: any;
t: any;
menuItems: object[];
location: string;
location: any;
}
class AdminHeader extends React.Component<IHeaderProps | any, any> {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment