我正在学习React。我发现我需要安装一些包来使用任何东西。React和节点安装是空的吗[没有Java中的库]?
我正在使用react-router和react-router-dom版本6.8.0,以便“路由”可以正常工作。要使用{withRouter},我需要将版本降级到5.2.0。
如果我这么做了,"路线"就没用了.
关于如何使用React作为前端语言,或者Angular或其他语言更好,有任何澄清吗?
下面是代码。我想通过单击某个链接从SearchWindow.js移动到Restaurants1.js。
App.js:
import './App.css';
import Dashboard from './components/Dashboard';
import Restaurants1 from './components/Restaurants1';
import {Routes, Route} from 'react-router-dom';
import { Component } from 'react';
export default class App extends Component {
render() {
return (
<>
<Routes>
<Route path="/" element={<Dashboard />} />
<Route path="/restaurants" element={<Restaurants1 />} />
</Routes>
</>
);
}
}
SearchWindow.js:
export default class SearchWindow extends Component {
const newTo = {
pathname: "/restaurants",
param1: "Par1"
};
const stationsDropDown = (
<View>
<Dropdown
data={this.state.enableStations ? this.state.stations : undefined}
style={styles.dropdown}
/>
<Link to={newTo} className="btn btn-primary">Order Food</Link>
</View>
);
}
Restaurants1.js:
import React, { Component } from 'react';
import {View,FlatList, Text, StyleSheet, Image} from 'react-native';
import Row from './Row'; //If it's on the same folder
import { useLocation, useParams } from "react-router-dom";
const image1 = require('../assets/icondelivery.PNG')
const image2 = require('../assets/icondelivery.PNG')
var data1 = [{title:"You image title", image: image1}, {title:"Your Image title",image: image2}]
class Restaurants1 extends Component{
constructor(){
super();
console.log("this.props = "+this.props.useParams);
}
render(){
return(
<View>
<FlatList
style={{flex:1}} //Don't forget this too
data={data1}
renderItem={({ item }) => <Row {...item}/>}
/>
</View>
)
}
}
export default () => (
<Restaurants1 params={useParams()} location={useLocation()} />
);
无法获取Restaurants1.js中param 1的值。
1条答案
按热度按时间z2acfund1#
所以,终于,解决了。
Restaurant1.js:
withRouter.js:
SearchWindow.js: