我有一个称为Dashboard的父组件,该组件被渲染为Route,如下所示:
const Routes = ({ authenticated }: { authenticated: boolean }) => (
<Switch>
<AuthenticatedRoute path="/home" exact={true} component={Dashboard} authenticated={authenticated} />
<UnauthenticatedRoute path="/login" exact={true} component={Login} authenticated={authenticated} />
<AuthenticatedRoute path="/onboarding" exact={true} component={Onboarding} authenticated={authenticated} />
<AuthenticatedRoute path="/meets" exact={true} component={Meets} authenticated={authenticated} />
<Route component={NotFound} />
</Switch>
)
export default Routes
Run Code Online (Sandbox Code Playgroud)
在Dashboard组件中,我还要呈现路线,该组件如下所示:
class Dashboard extends React.Component<IProps, {}> {
public render() {
return (
<div>
<Navigation />
<Route exact={true} path="/home" component={Home} />
<Route exact={true} path="/home/profile" component={Profile} />
<Route exact={true} path="/home/messages" component={Messages} />
HALLO
</div>
)
} …Run Code Online (Sandbox Code Playgroud) 通过书中的一些练习。必须将数组项打印到列表元素中。
这是本书提供的解决方案。
<!doctype html>
<html lang="en">
<head>
<title>Temperatures</title>
<meta charset="utf-8">
<script>
function showTemps() {
var tempByHour = new Array();
tempByHour[0] = 59.2;
tempByHour[1] = 60.1;
tempByHour[2] = 63;
tempByHour[3] = 65;
tempByHour[4] = 62;
for (var i = 0; i < tempByHour.length; i++) {
var theTemp = tempByHour[i];
var id = "temp" + i;
var li = document.getElementById(id);
if (i == 0) {
li.innerHTML = "The temperature at noon was " + theTemp;
} else {
li.innerHTML = "The temperature …Run Code Online (Sandbox Code Playgroud)