autoname
V2EX  ›  React

请问下各位大佬,编译后部署怎么访问不了其他路由

  •  
  •   autoname · May 18, 2020 · 1817 views
    This topic created in 2184 days ago, the information mentioned may be changed or developed.
    http://localhost:3000/main
    http://localhost:3000/login
    http://localhost:3000/admin

    调试模式下,本地都可以访问

    编译后部署到虚拟机,就访问不了,

    访问一直都是 login 默认路由页面。

    其他页面

    直接抛出 nginx 的 404 页面。

    也不是我自定的 react 路由里面的 404 页面


    `

    import React from 'react'
    import {BrowserRouter as Router,Route,Switch} from "react-router-dom"
    import App from '../App'

    import Home from '../test/Login'
    import Login from '../test/Login'
    import Admin from '../test/Admin'
    import Info from '../test/Info'
    import NoMatch from '../tool/No404'
    import Main from '../test/Main'
    //import Cir from '../tool/Circling'

    //https://blog.csdn.net/qq_42813491/article/details/92579240
    export default class Routers extends React.Component{

    componentDidMount() {
    //console.log('ddd');
    }

    render() {
    return(
    <Router>
    <App>
    <Switch>
    <Route path="/main" render={
    ()=>
    <Main>
    <Route path="/main/:values" component={Info} />
    </Main>
    }>
    </Route>

    <Route exact path="/" component={Home} />
    <Route path="/login" component={Login}/>
    <Route path="/admin" component={Admin} />
    <Route component={NoMatch}></Route>
    </Switch>
    </App>

    </Router>

    );
    }
    }`
    3 replies    2020-05-18 09:47:15 +08:00
    otakustay
        1
    otakustay  
       May 18, 2020
    因为你的 nginx 啥的没有配 try_files 规则吧
    https://segmentfault.com/a/1190000013218418
    qinxi
        2
    qinxi  
       May 18, 2020
    因为路由被 nginx 接管了
    autoname
        3
    autoname  
    OP
       May 18, 2020
    这。。。还要配置 nginx 规则。。。
    谢谢大佬,

    try_files $uri $uri/ $uri/index.html /$1/ /$1/index.html;
    解决了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1002 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 22:17 · PVG 06:17 · LAX 15:17 · JFK 18:17
    ♥ Do have faith in what you're doing.