You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+71
Original file line number
Diff line number
Diff line change
@@ -56,3 +56,74 @@ Make sure you have [Heroky CLI](https://devcenter.heroku.com/articles/heroku-cli
56
56
- Now you have to configure frame app to use the URL provided by Heroku like `https://<APP-NAME>.herokuapp.com/topcoder-micro-frontends-navbar-app.js` to load this microapp.
57
57
- NOTE: Authorization would not work because only predefined list of domain allowed by `accounts-app`.
58
58
59
+
### Cross microfrontend imports
60
+
61
+
This app exports functions to be imported by other microapps.
62
+
-`login` - redirects to login page
63
+
-`logout` - clears session storage and redirects to logout page
64
+
-`setAppMenu` - sets sidebar menu for the app by app's `path`
65
+
-`getAuthUserTokens` - returns a promise which resolves to object with user tokens `{ tokenV3, tokenV2 }`
66
+
-`getAuthUserProfile` - returns a promise which resolves to the user profile object
67
+
-`disableSidebarForRoute` - disable (remove) sidebar for some route
68
+
-`enableSidebarForRoute` - enable sidebar for the route, which was previously disabled
69
+
70
+
#### How to export
71
+
72
+
- To export any function we have to `export` in file [src/topcoder-micro-frontends-navbar-app.js](src/topcoder-micro-frontends-navbar-app.js).
73
+
- If we want to prepare some function for exporting, the good place to do so is inside [src/utils/exports.js](src/utils/exports.js).
74
+
- We have to bind actions before exporting.
75
+
- It's not recommended to export the whole Redux Store to keep only navbar responsible for updating it. It's better to create promises which would return some particular value from the store.
76
+
77
+
#### How to import
78
+
79
+
When we want to use methods exported in the navbar microapp in other apps we have to make sure that webpack would not process imports from navbar as it is handled by `importmaps`, see [Cross microfrontend imports](https://single-spa.js.org/docs/recommended-setup/#cross-microfrontend-imports).
80
+
81
+
##### How to import in React app
82
+
83
+
For example see https://github.com/topcoder-platform/micro-frontends-react-app
84
+
85
+
1. Add `@topcoder/micro-frontends-navbar-app` to `externals` in webpack config:
2. As `importmaps` only work in browser and don't work in unit test, we have to mock this module in unit tests. For example by creating a file `src/__mocks__/@topcoder/micro-frontends-navbar-app.js` with the content like:
93
+
```js
94
+
module.exports= {
95
+
login: () => {},
96
+
logout: () => {},
97
+
setAppMenu: () => {},
98
+
getAuthUserTokens: () =>newPromise(() => {}),
99
+
getAuthUserProfile: () =>newPromise(() => {}),
100
+
disableSidebarForRoute: () => {},
101
+
enableSidebarForRoute: () => {},
102
+
};
103
+
```
104
+
105
+
##### How to import in Angular app
106
+
107
+
For example see https://github.com/topcoder-platform/micro-frontends-angular-app
108
+
109
+
1. Add `@topcoder/micro-frontends-navbar-app` to `externals` in webpack config:
3. TODO: How to make e2e tests work for Angular? So far they fail with error `Module not found: Error: Can't resolve '@topcoder/micro-frontends-navbar-app'`
0 commit comments