question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'pathname' of undefined

See original GitHub issue

whenever 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:closed
  • Created 5 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ramadscommented, Oct 24, 2018

Thanks @webdevabhi solved my issue 😃

2reactions
webdevabhicommented, Oct 24, 2018

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Router: Cannot read property 'pathname' of undefined
I've just started learning React and got stuck at this error. Uncaught TypeError: Cannot read property ...
Read more >
Cannot read properties of undefined (reading 'pathname')
The error "Cannot read properties of undefined (reading 'pathname')" occurs when we don't set the to prop on a Link component in React...
Read more >
TypeError: Cannot read property 'pathname' of undefined #184
But I am getting a TypeError: Cannot read property 'pathname' of undefined error when simply following the docs.
Read more >
Cannot read properties of undefined (reading 'pathname')
TypeError : Cannot read properties of undefined (reading 'pathname'). Do anyone have experience with this error?
Read more >
typeerror: cannot read properties of undefined ... - You.com
pathname is undefined because you've not correctly accessed it from the (presumably) passed location prop from route props. You've missed the props part....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found