admin管理员组文章数量:1023758
I'm trying to do nested routing using react server. But I'm getting an error in the browser console stating
Uncaught TypeError: Cannot read property 'props' of undefined
Here is the react code
const App = () => {
return (
<div>
<h2>{'Nested Routing App'}</h2>
<ul>
<li>
<Link to="/view1">{'View1'}</Link>
</li>
</ul>
{this.props.children}
</div>
);
};
const View1 = () => {
return(
<h3>{'Wele to View1'}</h3>
);
};
render(
<Router>
<Route ponent={App} path="/">
<Route ponent={View1} path="/view1"></Route>
</Route>
</Router>,
document.getElementById('app'));
Any idea what might be wrong ?
I'm trying to do nested routing using react server. But I'm getting an error in the browser console stating
Uncaught TypeError: Cannot read property 'props' of undefined
Here is the react code
const App = () => {
return (
<div>
<h2>{'Nested Routing App'}</h2>
<ul>
<li>
<Link to="/view1">{'View1'}</Link>
</li>
</ul>
{this.props.children}
</div>
);
};
const View1 = () => {
return(
<h3>{'Wele to View1'}</h3>
);
};
render(
<Router>
<Route ponent={App} path="/">
<Route ponent={View1} path="/view1"></Route>
</Route>
</Router>,
document.getElementById('app'));
Any idea what might be wrong ?
Share Improve this question asked Jan 7, 2017 at 14:26 iJadeiJade 23.9k58 gold badges161 silver badges250 bronze badges1 Answer
Reset to default 6arrow functions do not have lexical this
. And functional ponents receive props as a function argument. So the right way to do this would be..
const App = (props) => {
return (
<div>
<h2>{'Nested Routing App'}</h2>
<ul>
<li>
<Link to="/view1">{'View1'}</Link>
</li>
</ul>
{props.children}
</div>
);
};
read more here https://facebook.github.io/react/docs/ponents-and-props.html
I'm trying to do nested routing using react server. But I'm getting an error in the browser console stating
Uncaught TypeError: Cannot read property 'props' of undefined
Here is the react code
const App = () => {
return (
<div>
<h2>{'Nested Routing App'}</h2>
<ul>
<li>
<Link to="/view1">{'View1'}</Link>
</li>
</ul>
{this.props.children}
</div>
);
};
const View1 = () => {
return(
<h3>{'Wele to View1'}</h3>
);
};
render(
<Router>
<Route ponent={App} path="/">
<Route ponent={View1} path="/view1"></Route>
</Route>
</Router>,
document.getElementById('app'));
Any idea what might be wrong ?
I'm trying to do nested routing using react server. But I'm getting an error in the browser console stating
Uncaught TypeError: Cannot read property 'props' of undefined
Here is the react code
const App = () => {
return (
<div>
<h2>{'Nested Routing App'}</h2>
<ul>
<li>
<Link to="/view1">{'View1'}</Link>
</li>
</ul>
{this.props.children}
</div>
);
};
const View1 = () => {
return(
<h3>{'Wele to View1'}</h3>
);
};
render(
<Router>
<Route ponent={App} path="/">
<Route ponent={View1} path="/view1"></Route>
</Route>
</Router>,
document.getElementById('app'));
Any idea what might be wrong ?
Share Improve this question asked Jan 7, 2017 at 14:26 iJadeiJade 23.9k58 gold badges161 silver badges250 bronze badges1 Answer
Reset to default 6arrow functions do not have lexical this
. And functional ponents receive props as a function argument. So the right way to do this would be..
const App = (props) => {
return (
<div>
<h2>{'Nested Routing App'}</h2>
<ul>
<li>
<Link to="/view1">{'View1'}</Link>
</li>
</ul>
{props.children}
</div>
);
};
read more here https://facebook.github.io/react/docs/ponents-and-props.html
本文标签: javascriptCannot read property 39props39 of undefinedReact RouterStack Overflow
版权声明:本文标题:javascript - Cannot read property 'props' of undefined - React Router - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745592261a2157958.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论