reactjs - 如何配置 Office-js excel react 插件以使用 react-router-dom 或替代解决方案?
问题描述
因此,我正在尝试使用 react 设置 Office-js excel 加载项(使用此处找到的 yeoman office-js 生成器https://github.com/OfficeDev/generator-office)并且在配置添加时遇到问题-in 使用多条路线。看起来不像传统的 React 路由开箱即用(目前正在尝试使用 react-router-dom)。有人知道我会怎么做吗?特别是,看看我应该如何配置某种路由、webpack.config.js 和 manifest.xml。
例如,想在 route=[baseUrl]/ 上加载类似 LandingComponent 的东西,以及在 [baseUrl]/signup 上加载类似 SignupComponent 的东西。
对于常规的旧 React,我正在尝试做的事情看起来像这样
const Routes = () => (
<div>
<Route path="/" exact component={LandingComponent} />
<Route path="/signup" exact component={SignupComponent} />
</div>
)
我怀疑需要修改的关键代码段可能涉及 webpack.config.js 中的某些内容(对于实际配置 webpack 来说非常新,不确定我是否需要与这个人打交道),
清单.xml
<DefaultSettings>
<SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/>
</DefaultSettings>
此外,我正在考虑做一些事情,比如从上面的 URL 中删除“.html”(目标是插件应该默认在“ https://localhost:3000/ ”加载登陆,你可以通过按钮导航到“ https://localhost:3000/signup ”,而插件当前默认加载“ https://localhost:3000/taskpane.html ”)。
对不起呕吐这个词,在这方面还是很新的,不知道什么是可能的,什么是不可能的!
解决方案
我遇到了同样的问题,我使用的解决方案基本上是遵循@Ragavan Rajan 的 usingHashRouter
而不是BrowserRouter
.
import {
HashRouter as Router,
Switch,
Route
} from "react-router-dom";
...
render() {
return (
<Router>
<div>
<Switch>
<Route exact path="/main" component={Home} />
</Switch>
</div>
</Router>
);
}
这个答案提供了更多的见解。最终,用于维护导航位置历史记录的两个函数设置为 null:
window.history.replaceState = null;
window.history.pushState = null;
当您尝试使用正常的浏览器路由时,如果由于这些功能不存在而抛出异常,而哈希路由不会发生这种情况。
推荐阅读
- r - 当负索引可能是整数(0)时,如何安全地从向量中删除任何内容?
- php - 如何在PHP中获取给定日期的时间前格式?
- r - 在 R 中调整图形大小闪亮
- reactjs - 我的 Axios 调用返回 404 错误,React/Express
- php - How to Reference File Two Directories Up, in Current File in PHP
- u-boot - u-boot 中的 CONFIG_SYS_EXTRA_OPTIONS 是什么?
- python - Rotating image makes the background dirty
- javascript - Get Dynamic Input ID javascript
- safari - Safari 内容拦截器对第 4 级的支持有多大限制?
- dart - Flutter 创建自己的类