How do I redirect into react-router from express?

后端 未结 1 865
抹茶落季
抹茶落季 2021-01-06 08:37

I\'m adding authentication into my app, which uses react-router. I\'ve patterned the client routing after the auth-flow example in react-router, but using passport instead o

1条回答
  •  北海茫月
    2021-01-06 09:05

    Config route on express to get all routes and routing with react-router, in this way, ejem. (I hope this can help you)

    server.js

    import express from 'express'
    import path from 'path'
    
    const app = express();
    
    app.use(express.static(__dirname + '/public'));
    app.get('*', (req,res) => res.sendFile(path.join(__dirname+'/public/index.html'))).listen(3000,() => console.log('Server on port 3000'))
    

    routes.jsx

    import React from 'react'
    import ReactDOM from 'react-dom'
    import { Router, Route, Link, browserHistory, IndexRedirect } from 'react-router'
    
    import App from '../views/app.jsx'
    
    const Routes = React.createClass({
        render(){
            return(
                
                    
                        
                        
                        
                        
                        
                    
                    
                        
                    
                
            );
        }
    });
    ReactDOM.render(, document.getElementById('app'))
    

    0 讨论(0)
提交回复
热议问题