Tag: react router v4

在服务器上呈现react-router v4和redux时,浏览器历史logging需要DOM错误

我试图为我的应用程序服务器呈现内容,使用react-router v4,redux和express,但我得到Browser history needs a DOM在terminalBrowser history needs a DOM错误。 我也使用react-router-config来保持我的路由更有条理。 看到一个解决scheme,build议应该在服务器上创build存储,所以我试图从store.js文件复制代码到服务器,但它没有工作。 我能做些什么来解决这个非常不愉快的错误? routes.js const routes = ( { component: App, routes: [ { path: '/', exact:true, component: Home }, { path: '/login', exact:true, component: Login }, { path: '/registration', exact:true, component: Registration }, { path: '/person/:id', exact:true, component: UserPage }, { path: '/myPage', exact:true, […]

在ReactJS中路由

任何人都可以向我解释路由如何在Reactjs中工作? browserHistory.push('/ location')只更新URL栏并且不redirect到它。 browserHistory.goBack()的作品,但只有当页面被访问之前,因此名称。 这让我很难理解browserHitory.goForward()如何工作? login成功后,我一直在尝试redirect到仪表板。 而已。 从我读到的,React不允许重新加载页面。 如果我们尝试刷新页面或在URL中写入地址,它将显示不能GET /path错误; 除非请求是在服务器上进行的。 我试图在服务器上创build路由,但无法获得如何实现它的语法。 我只在Node中进行编码,以便将res.send()发送到客户端应用程序。 我如何渲染这条路? 因为渲染到该path将意味着节点的App.js具有React应用程序的视图引擎。 我不知道是否足够清楚,但任何build议将是有益的。 谢谢。

React Routing工作在本地而不是Heroku

如果这个问题与本文所概述的不完全一样,我的问题就非常相似。 不幸的是,我无法使用它提供的策略来解决它。 所以这里是我自己的细节: 我正在使用创buildReact应用程序 , 反应路由器4 , Express和Heroku,并按照这里的说明build立与CRA的服务器。 在本地,我可以访问诸如myapp/about路线,但在build立并推送到heroku之后,这些404。 我可以通过UI导航到这条路线(例如,通过点击将路线推入history的菜单项),但是仅使用浏览器的地址栏无法导航到此路线。 此外,当我使用用户界面进行导航时,我没有看到与路线相关的任何networking活动,例如/about请求。 然而,当我改变地址栏,然后按回车,这产生了一个networking请求到上述路线。 以下是我的代码中的一些select片段: app.js <Switch> <Route exact path="/about" component={About} /> <Route path="/" render={props => <coolListContainer {…props}/>} /> </Switch> server.js if (process.env.NODE_ENV === 'production') { app.use(express.static('client/build')); } //…what some of my api routes look like: app.route('/api/verify') .post( async (req, res) => { try { await db.verifyCode(req.body) […]

在react-router v4中使用React IndexRoute

我正在使用在线教程学习React。 所以这是使用React Router的一个基本例子: <Router history={browserHistory}> <Route path="/" component={App}> <IndexRoute component={Home}/> <Route path="/home" component={Home}/> <Route path="/about" component={About}/> <Route path="/contact" component={Contact}/> </Route> </Router> 与我的应用程序组件: class App extends React.Component { render() { return ( <div> <ul> <li><Link to="home">Home</Link></li> <li><Link to="about">About</Link></li> <li><Link to="contact">Contact</Link></li> </ul> {this.props.children} </div> ) } } export default App; 但是,我使用IndexRoute时遇到了问题,因为它没有显示任何内容,所以我在npm上searchreact-router-dom v4的模块,里面没有IndexRoute。 相反,它使用这个: <Router> <div> <ul> <li><Link […]