V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
autoname
V2EX  ›  React

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

  •  
  •   autoname · 2020-05-18 09:37:40 +08:00 · 1307 次点击
    这是一个创建于 1438 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    2020-05-18 09:47:15 +08:00
    otakustay
        1
    otakustay  
       2020-05-18 09:42:18 +08:00
    因为你的 nginx 啥的没有配 try_files 规则吧
    https://segmentfault.com/a/1190000013218418
    qinxi
        2
    qinxi  
       2020-05-18 09:43:39 +08:00
    因为路由被 nginx 接管了
    autoname
        3
    autoname  
    OP
       2020-05-18 09:47:15 +08:00
    这。。。还要配置 nginx 规则。。。
    谢谢大佬,

    try_files $uri $uri/ $uri/index.html /$1/ /$1/index.html;
    解决了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3348 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:03 · PVG 20:03 · LAX 05:03 · JFK 08:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.