代码之家  ›  专栏  ›  技术社区  ›  greW

直接访问子路径

  •  5
  • greW  · 技术社区  · 7 年前

    <Main>
        <Switch>
            <Route exact path="/login" component={ LoginPage }/>
            <PrivateRoute path="/" component={ PrivatePages }/>
        </Switch>
    </Main>
    

    和内部 PrivatePages

    <div>
        <Switch>
            <Route exact path="/users/:id" component={ UsersPage }/>
        </Switch>
    </div>
    

    当我像这样访问它时 http://localhost:3000/users http://localhost:3000/users/someUserId <Link> http://localhost:3000/users/main.js (我不知道为什么它试图加载这个文件)我想这是来自谷歌的东西,我试图用谷歌搜索它,但我没有找到任何相关的。。。我无法准确地指出我错过了什么。

    谢谢

    1 回复  |  直到 7 年前
        1
  •  4
  •   GProst    7 年前

    好的,你的页面是空白的,因为它无法下载你的 main.js 初始化React应用程序的文件。

    对应于您的开发服务器输出公共路径(即 / 默认情况下)您应该能够下载 主要的js公司 使用以下URL: http://localhost:3000/main.js http://localhost:3000/users/main.js . 这是因为您指定了 src='main.js' <script> 在html文件中,这是一个相对路径。服务器采用当前URL路径( http://localhost:3000/users/ )并将其与 . 我们有 http://localhost:3000/users/main.js .

    <脚本(>); src src="/main.js" .