App not loading after install

Hi, I am trying to install my app onto a dhis2 instance and get this error:-

I ran the d2-app-scripts build and then installed onto the server. Any help would be appreciated.
The app runs when I connect to the server from my localhost when running d2-app-scripts start
Regards
Pooben

Hello @Pooben

Was your app bootstrapped from the DHIS2 app platform?

1 Like

Hi Gift

Yes, it was. I am also using react-router-dom and the first item routes to:-
<Route path=“/”
exact
element={}

Is the path correct or how do I get the dhis2 base url as the path? Locally it works. Is there a change if it is installed on a server?

Regards
Pooben

What type of router are you using? is it the BrowserRouter? If so, you can try specifying the basename when building the app which in your case would be ${baseUrl}/apps/${appname} where the base URL can be obtained from the useConfig hook and the app name is the name of your app specified as name in the d2.config.js or package.json.

Alternatively, you can use the HashRouter without specifying the basename.

2 Likes

Hi Gift

Thanks for your speedy response. I am using BrowserRouter.
Please could you provide mw with an example of how this would work?
This is the build script I run ‘yarn d2-app-scripts build’. Where do I use the useConfig hook?

Regards
Pooben

1 Like

Here is an example:

//...other imports
import {useConfg} from "@dhis2/app-runtime"




export function App(){
const {baseUrl} = useConfig();

const basename = `${baseUrl}/api/apps/predictiveanalytics`



return (
<BrowserRouter basename={basename}>
{//Routes}
</BrowserRouter>
)
}

2 Likes

@nnkogift Thank you.

1 Like