TypeError: Cannot read property 'pathname' of undefined
See original GitHub issuewhenever i am adding children to any routes in _nav.js file.
it is throwing error :
`AppSidebarNav.activeRoute node_modules/@coreui/react/es/SidebarNav.js:62 59 | }; 60 | 61 | AppSidebarNav.prototype.activeRoute = function activeRoute(routeName, props) {
62 | return props.location.pathname.indexOf(routeName) > -1 ? ‘nav-item nav-dropdown open’ : ‘nav-item nav-dropdown’; 63 | }; 64 | 65 | AppSidebarNav.prototype.hideMobile = function hideMobile() {`
I am using mac os x and running on chrome.
My codes are :
export default { items: [ { name: "Dashboard", url: "/dashboard", icon: "icon-speedometer" }, { name: "Users", url: "/users", icon: "icon-user", children: [ { name: "Feedback", path: "/users/feedback" } ] } ] };
my Routes file containes:
`import React from ‘react’; import Loadable from ‘react-loadable’
import DefaultLayout from “./Layout”;
function Loading() { return <div>Loading…</div>; }
const Dashboard = Loadable({ loader: () => import(“./pages/Dashboard/Dashboard”), loading: Loading });
const Users = Loadable({ loader: () => import(“./pages/Users/Users”), loading: Loading })
const routes = [ { path: ‘/’, exact: true, name: ‘Home’, component: DefaultLayout }, { path: ‘/dashboard’, name: ‘Dashboard’, component: Dashboard }, { path: ‘/users’, exact: true, name: ‘Users’, component: Users }, { path: ‘/users/feedback’, exact: true, name: ‘Users feedback’, component: Users }, ];
export default routes;`
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (1 by maintainers)
Top GitHub Comments
Thanks @webdevabhi solved my issue 😃
@ramads @toididau456 @abhishkekalia
i got one perfect solution. You have to pass the props of react-router-dom which include location, history, etc. Wheather your are keeping functional component or class component. Please make sure you are passing the all the props including BrowserRouter Props.
Please check in your component whether you are receiving the BrowserRouter props where you trying to use the sidebar.