通过MakeFile我找到了
PROJECT_ROOT = $(shell pwd)
它给了什么价值?
$SHELL给出shell并$PWD给出当前的工作目录但是$(shell pwd)给出了什么?
使用包
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
Run Code Online (Sandbox Code Playgroud)
App.js
class App extends Component {
constructor(props) {
super(props);
this.state = {
authState: null,
};
}
mutateAuthState = () => {
this.setState({
authState: true,
});
}
render() {
return (<Routes authState={this.state.authState} mutateAuthState={this.mutateAuthState} />)
}
}
Run Code Online (Sandbox Code Playgroud)
Routes.js
class Routes extends React.Component {
render() {
return (
<React.Fragment>
<BrowserRouter >
<Switch>
<Route path="/login" exact render={ () => <Login authState={this.props.authState}
mutateAuthState={this.props.mutateAuthState}/>
} />
<Route path="/" exact render={ () => <div><a href="/login" >login</a></div> } />
</Switch>
</BrowserRouter>
</React.Fragment>
); …Run Code Online (Sandbox Code Playgroud) https://reacttraining.com/react-router/web/guides/testing
React-router 测试文档对我来说有点晦涩难懂。
如何编写测试来检查路线是否呈现
一个组件。- APage.js
import React, { Component } from 'react'
export default class APage extends Component {
render() {
return (
<div>
A Page
</div>
)
}
}
Run Code Online (Sandbox Code Playgroud)
根据文档编写单元测试来检查。
路由.test.js
import React from 'react'
import { render } from "react-dom";
import APage from './APage'
import {MemoryRouter} from 'react-router-dom';
test("render route", () => {
render(
<MemoryRouter initialEntries={["/apage"]}>
<APage />
</MemoryRouter>
);
});
Run Code Online (Sandbox Code Playgroud)
它给出了一个错误,Invariant Violation:目标容器不是 DOM 元素。用于渲染。
如何编写基本测试,例如测试组件是否在路线上呈现。
使用React.js和React Router
import React, { Component } from 'react';
const PrivateRoute = ({ component: Component, ...rest }) => (
<Route {...rest} render={} />
)
Run Code Online (Sandbox Code Playgroud)
*{ component: Component, ...rest }*
..rest是使用扩展语法但是做了*component: Component*什么
有没有办法在视图(HTML 页面)中转储和显示 $scope 对象的所有属性,以便在 AngularJS 中进行调试。
const Home = () => <div>Home</div>
const App = () => {
const someVariable = true;
return (
<Switch>
{/* these are good */}
<Route exact path='/' component={Home} />
<Route
path='/about'
render={(props) => <About {...props} />}
/>
</Switch>
)
}
const About = (props) => {
return (
<div>
About
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
在代码示例中,位于
<Route
path='/about'
render={(props) => <About {...props} />}
/>
Run Code Online (Sandbox Code Playgroud)
当react遇到作为react-router一部分的Route组件的render prop时,它将传递什么props?
给定https://reactjs.org/docs/render-props.html上的文档,渲染道具是组件用来了解要渲染什么的功能道具,值传递给埋在Route声明中的道具吗?反应路由器
下列的
https://aws-amplify.github.io/docs/js/authentication#using-the-authenticator-component-directly
import { Authenticator} from 'aws-amplify-react'
import Amplify from 'aws-amplify';
import aws_exports from './aws_exports';
Amplify.configure(aws_exports);
const AppWithAuth = () => (
<Authenticator>
<App/>
</Authenticator>
)
export default AppWithAuth
Run Code Online (Sandbox Code Playgroud)
我正在尝试直接使用 Authenicator 组件。登录后如何显示退出按钮。
尝试遵循 https://github.com/richardzcode/Journal-AWS-Amplify-Tutorial/tree/master/step-02#sign-out-button
import { Authenticator , SignOut} from 'aws-amplify-react'
const AppWithAuth = () => (
<Authenticator>
<SignOut />
<App/>
</Authenticator>
)
Run Code Online (Sandbox Code Playgroud)
但注销按钮仍然不可见
https://reacttraining.com/react-router/web/example/auth-workflow
我在 react-router-dom 文档中实现了私有路由
function PrivateRoute({ authenticated, ownProps }) {
let {component:Component, ...rest} = ownProps
//PrivateRoute, If not authenicated ie false, redirect
return (
<Route
// JSX Spread sttributes to get path for Route
{...rest}
render={() => authenticated ? (
<Component />
) :
<Redirect
to={{pathname: "/" }}
/>
}
/>
);
}
export default PrivateRoute
Run Code Online (Sandbox Code Playgroud)
PrivateRoute 是一个从 Redux-Store 获取身份验证状态的连接组件。
我正在尝试使用 redux-mock-store 和从酶安装来测试连接的组件。
import configureStore from 'redux-mock-store'
const mockStore = configureStore()
const authStateTrue = {auth: {AUTHENTICATED: true}};
test('Private path renders …Run Code Online (Sandbox Code Playgroud) reactjs react-router react-router-redux react-router-v4 react-router-dom
我需要一个工作簿来打开时显示Combobox列表下拉列表.
工作簿中的组合框是一个表单控件,因此是一个形状.
似乎找不到相关的财产.
Square和Rectangle是扩展抽象类ShapesClass的类,定义了自己的Area方法.
abstract class ShapesClass
{
// Force Extending class to define this method
abstract public function Area();
}
class Square extends ShapesClass
{
private $side = 0;
function __construct($n)
{
$side = $n;
}
function Area()
{
echo $side * $side;
}
}
class Rectangle extends ShapesClass
{
var $length = 0;
var $width = 0;
function __construct($a,$b)
{
$length = $a;
$width = $b;
}
function Area()
{
echo $length * $width;
}
}
$listShapes = array();
$listShapes[0] = …Run Code Online (Sandbox Code Playgroud)