To initiate a page, a back-end developer needs to modify corresponding route function to include page_init endpoint and define the said action.
Then in order to load the SPA take the following steps:
- find the .py file that corresponds to the page we want to initiate (e.g. endpoints/reports/suppressions.py)
- search for the
@app.routecontroller with URL corresponding to the page you want to initiate e.g.@app.route('/reports/archive/', methods = ['GET', 'POST'])Inside it locate thegen_templatefunction and within it change the path to the page template to'vue-app/index.html'
Example commit: adding "Reports/Summary" page
Another example commit with an error and additional fix
- Add page component into
src/viewsfolder:- create a folder corresponding to the navigation group and page name in the
viewsfolder e.g.reports/archives - inside it create index.js containing the line
export { default } from './PageName.vue';
e.g.export { default } from './Archives.vue'; - add the base page template file, e.g.
vue-app\src\views\reports\archives\Archives.vue
- create a folder corresponding to the navigation group and page name in the
- Add path to router which will render the added component eg.
const ReportsArchivesAsync = () => import('@/views/reports/archives'); - Also in the router create a named path object inside the routes array e.g
{
path: 'archive',
name: 'ReportsArchives',
component: ReportsArchivesAsync,
meta: {
title: 'Archives',
},
},
- navigate to
vue-app\src\api\methods.js, duplicate and adjust an export async function in order to initiate a page with the provided data, e.g.
export async function getReportsArchivesInitialData() {
return camelCaseKeys((await client.get(INITIAL_DATA.endpoints.archives, {
params: {
action: 'page-init',
},
})).data.results);
}
5.Build the app (more details in this doc), commit changes upstream, test.