我正在使用react-router-dom v4.表单提交成功后如何重定向到页面?
我按照那个教程链接.然后我创建了自己的提交功能:
const submit=({email='',password=''})=>{
let error={};
let isError=false;
if(email.trim()===''){
error.email='Required';
isError=true;
}
else if(![ 'test@wp.pl' ].includes(email)){
error.email='User does not exist';
isError=true;
}
if(password.trim()===''){
error.password='Required';
isError=true;
}
else if(password!=='test'){
error.password='Wrong password';
isError=true;
}
if(isError){
throw new SubmissionError(error);
}
else{
//redirect to new page
}
}
Run Code Online (Sandbox Code Playgroud)
在评论的地方应该有一个重定向功能,但我不知道如何做到这一点.我试过放在那里:
<Redirect to="/pageAfterSubmit" push />但没有发生任何事.
我在index.js中的浏览器路由器如下所示:
<BrowserRouter >
<Provider store={store}>
<div>
<Route path="/" component={LoginForm}></Route>
<Route path="/markers" component={Markers}></Route>
<Route path="/contact" component={Contact}></Route>
</div>
</Provider >
</BrowserRouter>
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我有视频src的问题.在源代码中单击我的div(相机)后,我可以看到视频src正在正常更改,但视频没有播放.我该怎么办?
下面是我的组件 - streaming.component.ts(负责显示所选摄像机组件的视频)和camera.component.ts(用于查看带摄像机名称的图标)
streaming.component.ts
import {Component} from '@angular/core';
import {CameraComponent} from '../camera/camera.component';
@Component({
moduleId: module.id,
selector: 'streaming',
template: `
<camera cameraName="Kamera 1" (click)='cameraStream("sample.mp4")'></camera>
<camera cameraName="Kamera 2" (click)='cameraStream("sample2.mp4")'></camera>
<camera cameraName="Kamera 3" (click)='cameraStream("sample3.mp4")'></camera>
<camera cameraName="Kamera 4" (click)='cameraStream("sample4.mp4")'></camera>
<video width="800" controls>
<source src = "{{cameraSrc}}" type="video/mp4">
Your browser does not support HTML5 video.
</video>
<p>{{cameraSrc}}</p>
`,
directives: [CameraComponent]
})
export class StreamingComponent {
cameraSrc:string;
constructor() { }
cameraStream(chosenCamera :string){
this.cameraSrc=chosenCamera;
}
}
Run Code Online (Sandbox Code Playgroud)
视频正在运行,因为我放的时候
<source src = "{{cameraSrc}}" type="video/mp4">
Run Code Online (Sandbox Code Playgroud)
一切都好.
camera.component.ts
import { …Run Code Online (Sandbox Code Playgroud) 我正在使用 mac 并且我有一个脚本文件print_hello:
#!/bin/bash
echo hello
Run Code Online (Sandbox Code Playgroud)
如果我直接从带有./print_hello命令和 zsh 终端的目录运行它,它将正确打印 hello。我想将其添加为全局命令,因此print_hello在终端中写入应该打印“你好”。但我得到的是:
zsh: command not found: print_hello
Run Code Online (Sandbox Code Playgroud)
路径是正确的(我在 中对其进行了编辑.zshrc)。该文件具有适当的权限(我使用过chmod 755 print_hello):
? ~ echo $PATH
/Users/mateusz/bin:/usr/local/bin:/Users/mateusz/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/GE/bin:~/scripts
Run Code Online (Sandbox Code Playgroud)
并且print_hello文件在~/scripts
我可以运行脚本的唯一方法是直接从它的目录中运行。我该怎么办?我添加了一些别名.zshrc并且它们正在工作,那么为什么可执行脚本不起作用?
我想知道如何返回与 reducer 函数相同类型的对象:
function storeReducer(
state = INITIAL_APPLICATION_STATE,
action: Actions
): ApplicationState {
switch (action.type) {
case LOAD_USER_THREADS_ACTION:
return handleLoadUserThreadsAction(state, action);
default:
return state;
}
}
Run Code Online (Sandbox Code Playgroud)
我期望ApplicationState类型的对象,但使用这种方法:
StoreModule.forRoot({storeReducer})
Run Code Online (Sandbox Code Playgroud)
我正在使用密钥获取对象:
storeReducer:{ // object of type Application State}
Run Code Online (Sandbox Code Playgroud)
我期待获得对象(没有额外的 storeReducer 键):
{//object of type Application State}
Run Code Online (Sandbox Code Playgroud)
也尝试过,StoreModule.forRoot(storeReducer)但后来我得到了空对象,但它不起作用。