我正在使用 Typescript 进行 React。“重定向”似乎对我不起作用。我不知道是什么问题。
import * as React from "react"
import { TextField } from 'office-ui-fabric-react/lib/TextField';
import { PrimaryButton } from 'office-ui-fabric-react/lib/Button';
import store from "./ToDoStore"
import { Redirect} from "react-router-dom";
export class AddTodo extends React.Component {
refs: {
name: (HTMLInputElement);
description: (HTMLInputElement);
}
addTodo() {
store.addTodo({ name: this.refs.name.value, description: this.refs.description.value })
alert("Task added successfully");
<Redirect to="/home" push/>
}
render() {
return (
<div id="addtodo">
<TextField
label='Add Todo' ref="name"
/>
<br />
<TextField
label='Add Description' ref="description"
/>
<br />
<PrimaryButton …Run Code Online (Sandbox Code Playgroud)