我是 React 和 React Router 的新手。我正在使用 React Router v4 并遵循基于以前版本的教程 - 但我让它工作了(使用在 SO 上找到的一些内容和 React Router v4 文档上的一些内容)。
但有一件事困扰着我。
我有一个网址http://localhost:3000/#/bugs,它基本上加载了我所有错误的列表。但我也有可能的网址,如http://localhost:3000/#/bugs?priority=low&status=open ,它加载一组特定的网址。
网址本身可以正常工作并按预期完成工作。
奇怪的是,每当我输入http://localhost:3000/#/bugs?priority=low&status=open(或任何参数)时,该组件都会执行其工作,但 URL 地址栏显示http://localhost:3000/ #/bugs(尽管渲染显示了与优先级和状态相关的所有内容)。
不知何故,URL 位置栏发生了变化,但我不明白为什么。
这是我的 App.js
import React from 'react';
import ReactDOM from 'react-dom';
import {BugList} from './BugList';
import {Redirect} from 'react-router';
import {HashRouter as Router, Route} from 'react-router-dom';
const NoMatch = React.createClass({
render : function (){
return(
<h2>This path does not exist</h2>
);
}
});
ReactDOM.render(
( …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Angular4项目.
我正在尝试设置代码覆盖率.我创建了一个非常简单的小应用程序.
我读了我能找到的每一个可能的页面,但我迷失了.
如何在Angular4中设置代码覆盖率?
更新2: 我现在决定使用业力报道报道 https://www.npmjs.com/package/karma-coverage ,因此根据描述重写了业力配置文件.
包json更新到了.
测试正在运行并通过:
这是我的包json.
{
"name": "angular2-webpack",
"version": "0.0.1",
"description": "A webpack starter for Angular",
"scripts": {
"pretest": "npm run lint",
"start": "webpack-dev-server --inline --progress --port 8080",
"test": "karma start",
"build": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail",
"lint": "tslint --force \"src/**/*.ts\""
},
"license": "MIT",
"dependencies": {
"@angular/common": "4.1.2",
"@angular/compiler": "4.1.2",
"@angular/core": "4.1.2",
"@angular/forms": "4.1.2",
"@angular/http": "4.1.2",
"@angular/platform-browser": "4.1.2",
"@angular/platform-browser-dynamic": "4.1.2",
"@angular/router": "4.1.2",
"bootstrap": "^3.3.7",
"core-js": "2.4.1", …Run Code Online (Sandbox Code Playgroud) 我有一个异步 thunk,可以从 Web 服务中获取一些信息,它可以分派三种类型的操作
FETCH_REQUESTED
FETCH_SUCCEEDED
FETCH_FAILED
Run Code Online (Sandbox Code Playgroud)
最后,如果它成功了;它返回实际的响应,或一个错误对象。
我有一个组件应该检测操作是否失败,最好通过订阅FETCH_FAILED操作并根据错误类型显示错误消息(404/401 和其他状态代码)
FETCH_REQUESTED
FETCH_SUCCEEDED
FETCH_FAILED
Run Code Online (Sandbox Code Playgroud)
我对 redux 和 react 很陌生,所以我有点不确定我是否朝着正确的方向前进,任何帮助将不胜感激。
我想在组件中触发一个动作。这是一个演示组件,不需要Redux感知。路由器的实现是通过react-router-redux完成的。
main.js:
let store = createStore(rootReducer)
const history = syncHistoryWithStore(hashHistory, store)
class RenderClass extends Component {
render() {
return (
<Provider store={store}>
<Router history={history}>
<Route path="/" component={MainLayout}>
<Route name="employees" path="/employees" url="http://localhost:8080/" component={EmployeeTable}></Route>
<Route name="personalInformation" path="/personalInformation/:employeeId" url={URI} component={PersonalInformation} />
.....
</Route>
<Router>
</Provider>
);
}
}
Run Code Online (Sandbox Code Playgroud)
App.jsx:
import * as Actions from './action-creator';
const MainLayout = React.createClass({
render: function() {
const { dispatch, list } = this.props;
let actions = bindActionCreators(Actions, dispatch);
console.log(actions);
return (
<div className="wrapper">
<Header actions={actions} list={list} params={this.props.params} …Run Code Online (Sandbox Code Playgroud) 我在我的 React Native 应用程序中使用 expo 和 admob 实现了广告,但我想在没有加载广告时摆脱空白/阻塞空间。还没有找到任何例子。(除了横幅之外,我在该页面上有一个标题和滚动视图)。这就是 Admob 横幅的实现方式:
// Display a banner
<AdMobBanner
bannerSize="fullBanner"
adUnitID="ca-app-pub-3940256099942544/6300978111" // Test ID, Replace with your-admob-unit-id
testDeviceID="EMULATOR" />
Run Code Online (Sandbox Code Playgroud) 我想从我的减少动作文件中导航。第一个屏幕是登录屏幕,因此在单击登录按钮后将调用redux动作创建者,reduce生成新状态。因此,在执行该操作之后,我想重新调配到仪表板。
我在用
反应本机+ Redux +反应导航
登录组件文件(LoginCmp.js):
import React, { Component } from 'react';
import {
Text,
View,
ScrollView,
KeyboardAvoidingView
} from 'react-native';
import { connect } from 'react-redux';
import { fieldChange, LoginAction } from '../../actions';
import { Button, Section, Input, Alert } from '../Helpers';
LoginAction(){
const payload = {
email: this.props.email,
password: this.props.password
};
this.props.LoginAction(payload); // Action call
}
render() {
return (
<KeyboardAvoidingView
style={styles.container}
behavior="padding"
>
<View>
<ScrollView contentContainerStyle={styles.contentContainer}>
<Text style={styles.headerText}> Login </Text>
{this.alertMessage()}
<Section>
<Input
placeholder="email@gmail.com" …Run Code Online (Sandbox Code Playgroud) jsx ×3
react-native ×3
react-redux ×3
reactjs ×3
redux ×3
admob ×1
angular ×1
banner-ads ×1
expo ×1
karma-runner ×1
mobile ×1
react-router ×1
redux-thunk ×1