Rba*_*bar 1 javascript web-applications reactjs react-router react-router-redux
我是React的新手,看着这个ReactTraining.我想将我的一些路径设为私有(这样您只能在登录时查看它们).我能够很好地验证用户并将它们引导到新页面,但现在我想"保护"该页面,以便只有在登录后才能访问.我发现了一些似乎使用相同"PrivateRoute"的不同来源 "功能如下.到目前为止,一切似乎都很有效(并且有意义),除了以下代码的"...... rest"部分:
const PrivateRoute = ({ component: Component, ...rest }) => (
<Route {...rest} render={props => (
fakeAuth.isAuthenticated ? (
<Component {...props}/>
) : (
<Redirect to={{
pathname: '/login',
state: { from: props.location }
}}/>
)
)}/>
)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Uncaught Error: Cannot find module "./components/Login"
at webpackMissingModule (router.js:9)
at Object.<anonymous> (router.js:9)
at __webpack_require__ (bootstrap 18b9132…:555)
at fn (bootstrap 18b9132…:86)
at Object.<anonymous> (index.js:22)
at __webpack_require__ (bootstrap 18b9132…:555)
at fn (bootstrap 18b9132…:86)
at Object.<anonymous> (bootstrap 18b9132…:578)
at __webpack_require__ (bootstrap 18b9132…:555)
at bootstrap 18b9132…:578
webpackMissingModule @ router.js:9
(anonymous) @ router.js:9
__webpack_require__ @ bootstrap 18b9132…:555
fn @ bootstrap 18b9132…:86
(anonymous) @ index.js:22
__webpack_require__ @ bootstrap 18b9132…:555
fn @ bootstrap 18b9132…:86
(anonymous) @ bootstrap 18b9132…:578
__webpack_require__ @ bootstrap 18b9132…:555
(anonymous) @ bootstrap 18b9132…:578
(anonymous) @ bootstrap 18b9132…:578
webpackHotDevClient.js:233 Error in ./src/components/Login.js
Syntax error: Unexpected token (16:46)
14 |
15 |
> 16 | const PrivateRoute = ({ component: Component, ...rest }) => (
| ^
17 | <Route {...rest} render={props => (
18 | fakeAuth.isAuthenticated ? (
19 | <Component {...props}/>
@ ./src/router.js 25:13-42
Run Code Online (Sandbox Code Playgroud)
看来我正在导入我应该做的所有事情,所以我的想法是我没有应该安装的东西.
有谁知道我可能需要安装什么来解决此错误?
该价差...语法不是的一部分es2015或react通天预设.这是目前的第3阶段提案.要在React项目中支持传播,请安装babel stage 3插件:
npm install --save-dev babel-preset-stage-3
Run Code Online (Sandbox Code Playgroud)
并将其添加到您的.babelrc:
{
"presets": [
"es2015",
"react",
"stage-3"
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2712 次 |
| 最近记录: |