Это мое решение:
Я использую этот репозиторий для интеграции React в мою разработку
https://github.com/enuchi/React-Google-Apps-Script
Вот код:
Код для сервера:
code.js
import * as publicFunctions from './forms-utilities.js'
// Expose public functions
global.onOpen = publicFunctions.onOpen
global.showSidebar = publicFunctions.showSidebar
forms-utilities.js
// Use ES6/7 code
const onOpen = () => {
FormApp.getUi()
.createAddonMenu()
.addItem('Configure notifications', 'showSidebar')
.addItem('About', 'showAbout')
.addToUi()
}
const showSidebar = () => {
let ui = HtmlService.createHtmlOutputFromFile('sidebar').setTitle(
'Form Awesome',
)
FormApp.getUi().showSidebar(ui)
}
export {
onOpen,
showSidebar,
}
Код для клиента (React):
index.jsx
import React from 'react'
import {render} from 'react-dom'
import Sidebar from './components/sidebar'
render(
<Sidebar />,
document.getElementById('index'),
)
sidebar.jsx
import React from 'react'
import {BrowserRouter, Redirect, Route, Switch} from 'react-router-dom'
import PageOne from './pageone'
import PageTwo from './pagetwo'
export default class Sidebar extends React.Component {
render() {
return (
<BrowserRouter>
<Redirect to="/" />
<Switch>
<Route path="/" exact component={PageOne} />
<Route path="/pagetwo" exact component={PageTwo} />
</Switch>
</BrowserRouter>
)
}
}
pageone.jsx
import React from 'react'
import {Link} from 'react-router-dom'
export default class PageOne extends React.Component {
render() {
return (
<div>
<div>Page One</div>
<Link to="/pagetwo">Go to Page Two</Link>
</div>
)
}
}
pagetwo.jsx
import React from 'react'
import {Link} from 'react-router-dom'
export default class PageTwo extends React.Component {
render() {
return (
<div>
<div>Page Two</div>
<Link to="/">Back</Link>
</div>
)
}
}
Полный репозиторий можно посмотреть здесь: https://github.com/piavgh/apps-script-react-navigation-sample