2016-11-01 77 views
0

我对路线注册下面的代码在我的小学(main.tsx)入口点:阵营,路由器不会尊重深层链接

import * as React from "react"; 
import * as ReactDOM from "react-dom"; 
import { browserHistory, IndexRoute, Route, Router } from "react-router"; 

import { About } from "../about/about"; 
import { Home } from "../home/home"; 

ReactDOM.render(
    <Router history={browserHistory}> 
     <Route path="/" component={Home}> 
     </Route> 
     <Route path="/about/:id" component={About}> 
     </Route> 
    </Router>, 
    document.getElementById("main") 
); 

我也有进入,输出下面的代码, devServer在我webpack.config.js文件:

module.exports = { 
    entry: { 
     main: "./wwwroot/common/main.tsx", // Starting point of linking/compiling Typescript and dependencies, will need to add separate entry points in case of not deving SPA 
     common: [ "q", "react", "react-dom", "react-router" ] // All of the "chunks" to extract and place in common file for faster loading of common libraries between pages 
    }, 
    output: { 
     path: "./dist/", // Where we want to host files in local file directory structure 
     publicPath: "/", // Where we want files to appear in hosting (eventual resolution to: https://localhost:4444/) 
     filename: "[name].js", // What we want end compiled app JS file to be called 
    }, 

    devServer: { 
     contentBase: "./dist", // Copy and serve files from dist folder 
     port: 4444, // Host on localhost port 4444 
     https: true, // Enable self-signed https/ssl cert debugging 
     colors: true, // Enable color-coding for debugging (VS Code does not currently emit colors, so none will be present there) 
     historyApiFallback: { 
      index: "index.html" 
     } 
    }, 

每当我试图访问/约/ uniqueGuidHere直接或通过刷新,所有我收到的404(所有图片文件以及输出的常见的。 js文件和main.js文件)。其他.tsx文件中不存在其他.tsx文件,其中有我拥有链接的链接(在它们的最后链接为guid)。我错过了什么吗?是否需要其他东西来允许与反应路由器进行深度链接?

+0

作为一个供参考“的index.html”,在目录“./wwwroot/”的存在 –

回答

0

对于那些也遇到过这个问题的我,我找到了一个解决方案(至少对我的问题)。原来index.html文件有相对路径(与深度路径相反)。

例如,通过将“main.js”的“script src”从“./main.js”更改为“/main.js”,它开始工作(正在使用webpack-dev-server进行服务)。

来源的进一步阅读可以在这里找到:https://github.com/reactjs/react-router-tutorial/tree/master/lessons/10-clean-urls