acdlite / redux-router

Redux bindings for React Router – keep your router state inside your Redux store
MIT License
2.3k stars 216 forks source link

TypeError: Cannot read property 'location' of undefined React Router useRouteMatch issue #298

Open nikhilroy2 opened 4 years ago

nikhilroy2 commented 4 years ago

I can't solve this problem, "TypeError: Cannot read property 'location' of undefined " in my reactjs project. I am trying to nesting the url for blog post but not working it, and I have test it's math by console it's take the path but nesting showing error.

Below the code which I have tried but not solving

` import React, { Component } from 'react'; import { Router, Link, Switch, useRouteMatch } from 'react-router-dom'; export default function Blogs(){
const match = useRouteMatch(); console.log(match.path) return (

        <div className="container-fluid px-2 text-light">
            <div className="row no-gutters py-4 border_bottom_dotted">
                <div className="col-6 mp_0">
                    <h2 className="mp_0 ">
                        Latest Blogs
            </h2>
                </div>
                <div className="col-6 mp_0 text-right text-white-50">
                    {/* <img src= alt=""/> */}
                </div>
            </div>

            <Switch>
                <Router exact path={match.path}> <PostListing/> </Router>
                <Router  path={`${match.path}/post1`}> <PostListing/> </Router>
            </Switch>

        </div>

    )

}

const PostListing = ()=> { return (

)

}

const PostItem = (props) => { return (

{""}

{props.postTitle}

Post Date: {document.lastModified}
    </div>
)

}

///

`