Skip to content

Commit

Permalink
Added nav
Browse files Browse the repository at this point in the history
  • Loading branch information
jennytoc committed May 22, 2024
1 parent aefd80e commit 05db7fb
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/container/config/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const devConfig = {
devServer: {
port: 8080,
historyApiFallback: {
index: 'index.html'
index: '/index.html'
}
},
plugins: [
Expand Down
3 changes: 2 additions & 1 deletion packages/container/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const generateClassName = createGenerateClassName({
});

export default () => {
return (
return (
// Creates copy of browser history for us
<BrowserRouter>
<StylesProvider generateClassName={generateClassName}>
<div>
Expand Down
17 changes: 15 additions & 2 deletions packages/container/src/components/MarketingApp.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { mount } from 'marketing/MarketingApp';
import React, { useRef, useEffect } from 'react';
import { useHistory } from 'react-router-dom';

export default () => {
const ref = useRef(null);
const history = useHistory();

useEffect(() => {
mount(ref.current);
});
const { onParentNavigate } = mount(ref.current,{
onNavigate: ({ pathname: nextPathname }) => {
const { pathname } = history.location;

if (pathname !== nextPathname) {
history.push(nextPathname);
};
}
});

// Any time there's a change in browser history, we call on this
history.listen(onParentNavigate);
}, []);

return <div ref={ref} />
};
2 changes: 1 addition & 1 deletion packages/marketing/config/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const devConfig = {
devServer: {
port: 8081,
historyApiFallback: {
index: 'index.html'
index: '/index.html'
}
},
plugins: [
Expand Down
13 changes: 8 additions & 5 deletions packages/marketing/src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Switch, Route, BrowserRouter } from 'react-router-dom';
import { Switch, Route, Router } from 'react-router-dom';
import { StylesProvider, createGenerateClassName } from '@material-ui/core/styles';

import Landing from './components/Landing';
Expand All @@ -11,15 +11,18 @@ const generateClassName = createGenerateClassName({
productionPrefix: 'ma',
});

export default () => {
return <div>
export default ({ history }) => {
return (
<div>
<StylesProvider generateClassName={generateClassName}>
<BrowserRouter>
{/* Creating a memory history */}
<Router history={history}>
<Switch>
<Route exact path="/pricing" component={Pricing} />
<Route path ="/" component={Landing} />
</Switch>
</BrowserRouter>
</Router>
</StylesProvider>
</div>
)
};
28 changes: 21 additions & 7 deletions packages/marketing/src/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { createMemoryHistory, createBrowserHistory } from 'history';
import App from './App';

// const root = ReactDOM.createRoot(document.getElementById("root"));

// Mount function to start up app
const mount = (el) => {
const mount = (el, { onNavigate, defaultHistory }) => {
const history = defaultHistory || createMemoryHistory();
if (onNavigate) {
history.listen(onNavigate);
};

ReactDOM.render(
<App />,
<App history={history}/>,
el
)
}
);

return {
onParentNavigate({ pathname: nextPathname }) {
const { pathname } = history.location;
if (pathname !== nextPathname) {
history.push(nextPathname);
}
}
};
};

// If in dev mode and isolated, then call mount immediately
if (process.env.NODE_ENV === 'development') {
const devRoot = document.querySelector('#_marketing-dev-root');
if (devRoot) {
mount(devRoot)
mount(devRoot, { defaultHistory: createBrowserHistory() });
}
};

Expand Down

0 comments on commit 05db7fb

Please sign in to comment.