小编rav*_*l91的帖子

如何使用 react-router 使用私有路由?

我想使用身份验证建立安全路由。我已经在 App.jsx 文件中定义了路由。我正在使用“路由”来定义要呈现的组件。

在 App.jsx 中

<Route 
    path='/dashboard'
    exact={true}
    render={(props) => <Dashboard {...props} user={user} 
    handleChildFunc={this.handleChildFunc}/>}
/>
Run Code Online (Sandbox Code Playgroud)

上面的代码没有任何问题。我想让它像下面一样安全。

<PrivateRoute 
    path='/dashboard'
    exact={true}
    render={(props) => <Dashboard {...props} user={user} 
    handleChildFunc={this.handleChildFunc}/>}
/>
Run Code Online (Sandbox Code Playgroud)

在 PrivateRoute.jsx 中

const PrivateRoute = ( props ) => {
  const user = "token from cookie"; // i will fetch token stored in cookie
  if(user !== null) {
    return <Route   />;
  }
  else {
    return <Redirect to="login" />
  }
}
Run Code Online (Sandbox Code Playgroud)

如果令牌存在,则呈现组件。否则,重定向到 /login。

reactjs react-router

3
推荐指数
2
解决办法
5562
查看次数

在ReactJS中使用grid-template-columns,内联样式

CSS我尝试在组件中使用网格React,但在第一个破折号中出现错误grid-template-columns,有什么想法为什么会发生这种情况吗?

<div style={{display:'grid', grid-template-columns: '1fr 1fr'}}>
Run Code Online (Sandbox Code Playgroud)

css inline-styles reactjs

3
推荐指数
1
解决办法
7273
查看次数

如何使用react Stable版本安装React Native

我尝试使用React Stable版本安装React native,但它安装了React:16-alpha

"dependencies": {
    "react": "16.0.0-alpha.6",
    "react-native": "0.44.0"
}
Run Code Online (Sandbox Code Playgroud)

那么如何使用React Stable版本安装React-native?

javascript reactjs react-native

2
推荐指数
1
解决办法
1326
查看次数

使用 async/await 时未定义 regeneratorRuntime

我得到一个

“regeneratorRuntime 未定义”

尝试在项目中使用async/await时。

我的babelrc文件目前是这样的:

{
    "presets": ["env", "react"],
    "plugins": [
        "transform-runtime",
        "transform-object-rest-spread"
    ]
}
Run Code Online (Sandbox Code Playgroud)

我的package.json是:

{
    "name": "****",
    "version": "1.0.0",
    "description": "****",
    "main": "index.js",
    "author": "****",
    "license": "UNLICENSED",
    "private": true,
    "scripts": {
        "start": "yarn build && nodemon server/index.js --ignore dist/ --ignore public/",
        "watch": "parcel watch public/index.html --public-url /",
        "build": "parcel build public/index.html --public-url /",
        "test": "jest"
    },
    "dependencies": {
        "@babel/runtime": "^7.5.5",
        "axios": "^0.19.0",
        "express": "^4.17.1",
        "express-validator": "^6.1.1",
        "react": "^16.9.0",
        "react-dom": "^16.9.0", …
Run Code Online (Sandbox Code Playgroud)

javascript babeljs

2
推荐指数
1
解决办法
3885
查看次数

已声明React Router,但无法正常工作

您好,我希望它InstrumentPage#/访问时以无道具的形式呈现,但在#/ipb访问通过时ipb作为props实体。但这不起作用。

  render() {
    return (<React.Fragment>
      <HashRouter>
        <Switch>
          <Route path='/' render={(props) => <InstrumentPage {...props} />}/>
          {Object.keys(AppConfig).forEach((property) =>
            <Route path={property} render={(props) => <InstrumentPage {...props} entity={property} />} />)
          }
        </Switch>
      </HashRouter>
    </React.Fragment>);
  }
Run Code Online (Sandbox Code Playgroud)

AppConfig

const AppConfig = {
  pb: {
    header: 'PBHeader',
    body: 'PBBody',
  },
  ipb: {
    header: 'IPBHeader',
    body: 'IPBBody',
  },
};    
export default AppConfig;
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-router react-router-dom

2
推荐指数
1
解决办法
48
查看次数

如何更改反应引导模式的背景颜色

我想更改反应引导模式弹出窗口的背景颜色。

我的模态代码是 -

<Modal
    show={this.state.show}
    onHide={this.handleClose}
    dialogClassName="modal-90w public-profile-modal-class"
    size='lg'
    aria-labelledby="example-custom-modal-styling-title"
>
Run Code Online (Sandbox Code Playgroud)

那么如何改变呢?

reactjs react-bootstrap

2
推荐指数
2
解决办法
9779
查看次数

How to show hand hover on ReactTable rows in "React.js"

<div>
     <ReactTable
         data={this.state.listFruitData}
         columns={columns}
         defaultPageSize={10}
         getTrProps={onRowClick}
     />
</div>
Run Code Online (Sandbox Code Playgroud)
  1. I am actually populating data(listFruitData) in ReactTable from post request call.
  2. My requirement is I need to first select row of ReactTable may be using some background color so that it looks like the row is selected
  3. While I am selecting row I should get hand(icon) hover on ReactTable row
  4. How to do this?

reactjs

2
推荐指数
1
解决办法
2832
查看次数

When does the code outside React Component class in a JS file run?

Say I have a JS file contains 2 React Component class definition and a bunch of other things:

// a file called OuterComponent.react.js

import xxx from xxx;
import yyy from yyy;

// When does these run?
let a = 0;
a = 1;

export default class OuterComponent extends React.PureComponent<> {
  render() {
    return (
      <View>
       <InnerComponent />
      </View>
    );
  }
}

class InnerComponent extends React.PureComponent<> {
  //... something
}
Run Code Online (Sandbox Code Playgroud)

Questions

  1. When will the declaration and value setting code for 'a' …

javascript reactjs react-native

2
推荐指数
1
解决办法
736
查看次数

如何在反应中重置选择下拉值

我有一个 html 下拉选择控件,并且已将第一个选项值添加为Select. 还有其他几个选项可以从下拉菜单中选择。现在我想重置下拉值并将其设置回Select.

我如何在 React 中做到这一点?

这是我的代码

<select className="form-control" ref="Auditee" name="Auditee" onChange={this.handleChange.bind(this)}>
                <option>Select</option>
                {this.renderAuditee()}
              </select>
<button type="button" className="btn btn-primary" onClick={this.handleClear}>Clear</button>



renderAuditee(){
  let Auditeefiltered = this.state.review1data.map(element=> element.EEECPM).filter((value, index, self) => self.indexOf(value) === index)

  return Auditeefiltered.map(element=>
   <option>{element.toString().replace(/\[.*?\]/,'')}</option>
  )
}


handleClear(e){
 e.preventDefault();

    this.setState({
        filterData:[],
        filter: false
 });
Run Code Online (Sandbox Code Playgroud)

我不知道我应该如何重置选择下拉列表。任何帮助都会有所帮助

javascript reactjs

1
推荐指数
1
解决办法
4914
查看次数

React BrowserRouter 路由在部署后不起作用

我有一个简单的网站,有 2 个可以离线工作的链接,但是如果我部署它并将其上传到网站上,那么第一页工作正常,但是当我单击“添加链接”时,它会给我 404 并且列表链接工作正常,两个链接都可以在离线状态下正常工作

<a href="/react/">List</a>
<a href="/react/Add">Add</a>
Run Code Online (Sandbox Code Playgroud)

路由器文件

ReactDOM.render(
  <BrowserRouter>
    <Route path="/react/" exact component={List}/>
    <Route path="/react/Add" exact component={Add}/>
  </BrowserRouter>,
  document.getElementById('root')
);
Run Code Online (Sandbox Code Playgroud)

包.json

{
    "name": "axios1",
    "version": "0.1.0",
    "homepage":"http://aroratour.com/react/",
Run Code Online (Sandbox Code Playgroud)

routes hyperlink reactjs

1
推荐指数
1
解决办法
3540
查看次数