How to configure Office-js excel react add-in to use react-router-dom or alternative solutions?

后端 未结 1 1572
鱼传尺愫
鱼传尺愫 2021-01-26 19:41

So I\'m trying to set up an Office-js excel add-in using react (using the yeoman office-js generator found here https://github.com/OfficeDev/generator-office) and am running int

相关标签:
1条回答
  • 2021-01-26 20:11

    I had the same issue, and the solution I used was essentially following @Ragavan Rajan's solution of using HashRouter instead of 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>
    );
    }
    

    This answer provides more insight. Ultimately, two functions which are used in maintaining a history of where you have navigated are set to null:

    window.history.replaceState = null;
    window.history.pushState = null;
    

    and when you try to use the normal browser routing, an exception if thrown because these functions don't exist, which doesn't happen with Hash Routing.

    0 讨论(0)
提交回复
热议问题