-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathsetup-app.ts
More file actions
70 lines (61 loc) · 3.05 KB
/
setup-app.ts
File metadata and controls
70 lines (61 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (c) 2024, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
// Third-Party
import React from 'react'
import {RouteProps} from 'react-router-dom'
// Platform Imports
import {ApplicationExtension} from '@salesforce/pwa-kit-extension-sdk/react'
// Local Imports
import {Config} from './types'
import SamplePage from './pages/sample'
import extensionMeta from '../extension-meta.json'
// By importing this SampleComponent via the overridable loader,
// you intentionally make it available for other extensions or a user project to override the file
import withSampleComponent from 'overridable!./components/with-sample-component'
// Then others can override it by creating a file in this overrides directory:
// - for another extension: src/overrides/<name of your extension>/components/with-sample-component.tsx
// - for a user project: app/overrides/<name of your extension>/components/with-sample-component.tsx
class Sample extends ApplicationExtension<Config> {
static readonly id = extensionMeta.id
/**
* Use this method to wrap or enhance your PWA-Kit application using [React higher-order components](https://legacy.reactjs.org/docs/higher-order-components.html).
* You can use this to add visual treatments to your application, change the props that are supplied to the application component
* or add things like providers and contexts to be used throughout your app.
*/
extendApp<T extends React.ComponentType<T>>(
App: React.ComponentType<T>
): React.ComponentType<T> {
// For example, you can extend the React app by wrapping your project's App with this SampleComponent
return withSampleComponent(App)
}
/**
* This method is used to make changes to the PWA-Kit application routes. If your extension adds a new page to the application
* then you can add it to the router here. The routes passed to this method is an accrued list of routes that have been added
* from extensions applied before it. It is called during the `getRoutes` phase on both the server and the client.
*
* NOTE: If you instead want to modify a list of all the routes, refer to the `beforeRouteMatch` below.
*/
extendRoutes(routes: RouteProps[]): RouteProps[] {
return [
{
exact: true,
path: this.getConfig().path,
component: SamplePage
},
...routes
]
}
/**
* This method is used on the server during the rendering pipeline. It's provided a list of all the routes that your application
* is configured with, including those defined in the base application and those added by all the extensions. You can use this
* method to modify these routes in any way you want, but you must return an array of routes as a result.
*/
beforeRouteMatch(allRoutes: RouteProps[]): RouteProps[] {
return allRoutes
}
}
export default Sample