我们有菜单,当有人单击按钮时,应该加载新的组件,但这并不是每次都发生。基本上,我们有2个Browserouters。在Intlprovider所在的App.js中为1,在菜单所在的Home.js中为1。我将在此处提供代码。我们还有其他版本的应用程序,它不使用react-intl,并且运行良好。请帮忙。
试图将intlProvider的位置从app.js更改为index.js,但这无法解决问题。
Home.js渲染方法:
render() {
return (
<IntlProvider
locale={this.state.lang}
messages={messages[this.state.lang]}
>
<React.Fragment>
<Router>
<Switch>
<Route
path="/Pocetna"
component={() => (
<Pocetna
handleLangS={this.handleLangS}
handleLangE={this.handleLangE}
/>
)}
/>
<Route
path="/Home"
component={() => (
<Home
handleLangS={this.handleLangS}
handleLangE={this.handleLangE}
/>
)}
/>
<Route path="/" component={LoginForms} />
{this.props.children}
</Switch>
</Router>
</React.Fragment>
</IntlProvider>
);
}
Home.js菜单(所有更改菜单的按钮都在Sidemenu组件中):
<Router>
<Switch>
<SideMenu
funkcija={this.PromenaAkcije}
ime={this.state.ime}
prezime={this.state.prezime}
slika={this.state.slika}
uloga={this.state.uloga}
RoditeljPromeniSliku={this.PromeniSliku}
podaciOProjektima={this.state.sviProjekti}
stigle={this.state.stigle}
promenjenaSlika={this.PromenjenaSlika}
brojRoditelja={this.state.brojRoditelja}
kompanija={this.state.kompanija}
definisiProjekat={this.definisiProjekat}
/>
<Route
exact={true}
path="/home/dashboard"
component={Dashboard}
/>
<Route
exact={true}
path="/home/adduser"
component={AddUser}
/>
<Route
exact={true}
path="/home/projects"
component={Projects}
/>
<Route
strict
exact={true}
path="/home/addproject"
component={AddProject}
/>
<Route
strict
exact={true}
path="/home/addsubproject"
component={AddSubproject}
/>
<Route
exact={true}
path="/home/project"
component={Project}
/>
<Route
exact={true}
path="/modal/newSpriteModal"
component={newSpriteModal}
/>
<Route
exact={true}
path="/home/myprofile"
component={MyProfile}
/>
<Route exact={true} path="/home/users" component={Users} />
<Route exact={true} path="/home/task" component={Task} />
</Switch>
</Router>