【问题标题】:React Router base URL issue and link tag issueReact Router 基本 URL 问题和链接标签问题
【发布时间】:2016-12-30 15:23:44
【问题描述】:

我在 IIS 中托管的 ASP.NET Web 窗体中有一个现有应用程序。现在我在根目录下创建了一个名为 mobile 的新目录。网址就像 - http://domainname/mobile

应用程序是使用 React、Redux 和 React Router 编写的。现在运行应用程序,我在 Routes.js 中进行了如下更改 -

<Router history={history}>
    <Route path='/mobile' component={App}>
        <Route path='/thankyou' component={ThankYou} />
    </Route>
</Router>

主页已正确加载,因为根组件的路径为“/mobile”。但是当我尝试使用指向thankyou的链接标签访问thankyou组件时。它没有用。

我尝试了各种更改 - 使用 react-router github 上提供的基本名称或历史记录或各种建议的解决方案,但这些也不起作用。我在 package.json 中的库版本

"react": "15.0.2",
"react-dom": "15.0.2",
"react-redux": "4.4.5",
"react-router": "2.4.0",
"react-router-redux": "4.0.4",

谁能提供一个将baseURL设置为“/mobile”的工作解决方案?

可能重复 - React Router

【问题讨论】:

    标签: reactjs react-router


    【解决方案1】:

    如果 /mobile url 由服务器而不是前端提供,您的根路由应该是 /,如:

    <Route path="/" component={ App }>
        <Route path="thankyou" component={ ThankYou } />
    </Route>
    

    这使得/mobile/#/thankyou 可以访问。

    【讨论】:

    • 我没有使用哈希历史。这将无法直接访问,因为没有这样的页面。我尝试重写 URL,以便每当 /mobile 存在时,我的页面都会作为输出返回。进行此重写更改后,我可以直接访问该页面。但是 仍然无法正常工作。它仍然指向 domain/thankyou 它应该指向 domain/mobile/thankyou
    猜你喜欢
    • 1970-01-01
    • 2018-09-05
    • 2022-11-22
    • 2016-01-22
    • 2011-10-21
    • 2021-01-09
    • 1970-01-01
    • 2015-02-23
    • 2018-01-01
    相关资源
    最近更新 更多