代码之家  ›  专栏  ›  技术社区  ›  Alessio Chiffi

当我在Github中发布到自定义域时,react router没有呈现path='/。

  •  2
  • Alessio Chiffi  · 技术社区  · 6 年前

    我在Github有一个repo,我已经将自定义域设置为www.alessiochf.com。

    应用程序没有按照以下代码呈现主路线

    import React from 'react'
    import { Switch, Route } from 'react-router-dom'
    import Home from './Home'
    import About from './About'
    import PhotoApp from './PhotoApp'
    import ScrollToTop from './scrollToTop'
    
    
    const Main = () => (
      <main>
        <Switch>
         <ScrollToTop>
            <Route path='/' component={Home}/>
            <Route path='/PhotoApp' component={PhotoApp}/>
            <Route path='/About' component={About}/>
          </ScrollToTop>
        </Switch>
      </main>
    )
    
    export default Main

    这是我的package.json文件

    {
      "name": "alessioch",
      "description": "Portfolio in React.js",
      "homepage": "http://www.alessiochf.com",
      "version": "0.0.0",
      "dependencies": {
        "react": "15.5.3",
        "react-dom": "15.5.3",
        "react-router-dom": "4.1.1",
        "react-scroll-parallax": "^1.3.5",
        "surge": "^0.20.1"
      },
      "devDependencies": {
        "gh-pages": "^1.2.0",
        "react-scripts": "1.0.0"
      },
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject",
        "predeploy": "npm run build",
        "deploy": "gh-pages -d build"
      }
    }

    我错过什么了吗?谢谢

    1 回复  |  直到 6 年前
        1
  •  1
  •   Tholle    6 年前

    确保设置 exact true Home 路线:

    <Route exact path='/' component={Home}/>