Archives : April-2018

Here are the routes. I am trying to get the param like /fetchdata/someid and I tried this.props.match.params.id this is where is says that: property ‘id’ does not exist on type ‘{}’ import * as React from ‘react’; import { BrowserRouter, Route, Switch } from ‘react-router-dom’; import { Layout } from ‘./components/Layout’; import { Home } ..

Read more

I have a <UserListComponent /> which outputs one <Contact /> component and list of contacts presentated by <Contacts />. The problem is that in the test for <UserListComponent /> when I try to mount it, test outputs an error Invariant Violation: You should not use <Route> or withRouter() outside a <Router> withRouter() is used in ..

Read more

If you have URLs in your app that can change (e.g /profile/1 and /profile/2, how do you access that from this.props.location.pathname? In my Profile component I have a componentDidMount method like so: componentDidMount () { if (this.props.location.pathname === ‘profile/:id/’) { console.log(‘is profile’) } else { console.log(‘is not profile’) } } Which returns is not profile ..

Read more

I’m using react and I came across a problem, albeit an aesthetic problem and not a functional one. I am generating react-routes from an API of names. The route works fine, but as the names have spaces, they appear in the url as: example.com/lookup/David%20Attenborough Example: <Link to='{/lookup/’ + props.data.name}>{props.data.name}</Link> Is there a clever way I ..

Read more

Im using [email protected] I have this <Route path=’/login’ component={ Login } /> <Route exact path=’/’ component={ Home } /> Is there a way to define default route as in [email protected]? It is also necessary this “default route” does not pass if any other matched. Because if I will add <Route path=’/login’ component={ Login } /> ..

Read more

Context I’m using React Router. Most of my routes/pages include some sort of .css for theirs components + the implicit antd (UI framework) stylesheet: import ‘../styles.css’; This way all views declared in my App automatically inherit these stylesheets. Question I now need to have a route/page that starts off clean from any other stylesheet. Is ..

Read more

I am making a react app using routers and I’m getting the following error: React TypeError: WEBPACK_IMPORTED_MODULE_0_react.PropTypes is undefined How can I avoid it? Here the code for the 2 routers, post and profile: Posts import React,{Component} from ‘react’; class Posts extends Component{ render(){ return <div> Posts </div> } } export default Posts; Profile import ..

Read more

Refused to execute script from ‘http://localhost:8080/edit/bundle.js‘ because its MIME type (‘text/html’) is not executable, and strict MIME type checking is enabled. I am using react-router and i got this error while using <Route path=”/edit/:id” component={EditExpensePage} /> it is working fine with just /edit but giving error on /edit/:id. I don’t understand why this is happening. ..

Read more