alpertuna / react-metismenu-router-link

Router link extension for `react-metismenu` menu component.
https://www.npmjs.com/package/react-metismenu-router-link
MIT License
8 stars 14 forks source link

TypeError: Cannot read property 'history' of undefined #12

Open ademahendra opened 6 years ago

ademahendra commented 6 years ago

Get error Cannot read property 'history' of undefined on RouterLink

"react": "^16.3.2", "react-dom": "^16.3.2", "react-metismenu": "^1.4.0", "react-metismenu-router-link": "^2.1.0", "react-router-dom": "^4.2.2",

/**
 * React Starter Kit (https://www.reactstarterkit.com/)
 *
 * Copyright © 2014-present Kriasoft, LLC. All rights reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.txt file in the root directory of this source tree.
 */
import React, { Component } from 'react';
import MetisMenu from 'react-metismenu';
import RouterLink from 'react-metismenu-router-link';

const content = [
  {
    icon: 'icon-class-name',
    label: 'Label of Item',
    to: 'login',
  },
  {
    icon: 'icon-class-name',
    label: 'Master',
    content: [
      {
        icon: 'icon-class-name',
        label: 'Kandang',
        to: 'about',
      },
    ],
  },
];

class Navigation extends Component {
  render() {
    return (
      <div>
        <MetisMenu content={content} LinkComponent={RouterLink} />
      </div>
    );
  }
}

export default Navigation;
TypeError: Cannot read property 'history' of undefined
    at RouterLink.componentWillMount (D:\react\farm-starter\node_modules\react-metismenu-router-link\lib\RouterLink.js:50:27)
    at processChild (D:\react\farm-starter\node_modules\react-dom\cjs\react-dom-server.node.development.js:2154:16)
    at resolve (D:\react\farm-starter\node_modules\react-dom\cjs\react-dom-server.node.development.js:2048:5)
    at ReactDOMServerRenderer.render (D:\react\farm-starter\node_modules\react-dom\cjs\react-dom-server.node.development.js:2333:22)
    at ReactDOMServerRenderer.read (D:\react\farm-starter\node_modules\react-dom\cjs\react-dom-server.node.development.js:2307:19)
    at Object.renderToString (D:\react\farm-starter\node_modules\react-dom\cjs\react-dom-server.node.development.js:2679:25)
    at _callee$ (D:\react\farm-starter\src\server.js:163:1)
    at tryCatch (D:\react\farm-starter\node_modules\regenerator-runtime\runtime.js:62:40)
    at Generator.invoke [as _invoke] (D:\react\farm-starter\node_modules\regenerator-runtime\runtime.js:296:22)
    at Generator.prototype.(anonymous function) [as next] (D:\react\farm-starter\node_modules\regenerator-runtime\runtime.js:114:21)
    at step (D:\react\farm-starter\build\server.js:2623:221)
    at _next (D:\react\farm-starter\build\server.js:2623:409)
    at <anonymous>
alex-brambila commented 5 years ago

I'm getting the same error w React 16. Worked fine w 15. Starting to think it may not be compatible w 16??

jhillhouse92 commented 5 years ago

I'm not sure if this is active or not, but I had the same issue after using react-router 4.4.0-beta+ which removed the context API. I created the pr: https://github.com/alpertuna/react-metismenu-router-link/pull/13