I need to open a weweb page using a Custom Javascript action in a workflow. That page has a URL Parameter in its url: https://yourdomain.com/app/inventory/11
This helpful thread demonstrated how to use wwLib.goTo(...) with a query parameter: wwLib.goTo('your_page_uuid', {your_query_name:'your query value'})
That thread was written last July, well before URL params were introduced to WeWeb.
I’ve tried to follow the same pattern for URL params, but when I run the same action, WeWeb opens the correct page with the default param value (11 in the screenshot above)
On the deployed app wwLib.wwApp.goTo(path, query) expects the path including path parameter values as first argument, opposite to the pageId in the editor version.
A general function you could build upon this might look like this:
function navigateToPage(pageId, params = {}, query = {}) {
const inEditor = globalContext.browser?.environment === 'editor';
if (inEditor) {
const editorParams = Object.fromEntries(
Object.entries(params).map(([key, value]) => [
`wwParam-${key}`,
String(value)
])
);
return wwLib.wwApp.goTo(pageId, {
...query,
...editorParams
});
}
const route = wwLib.wwPageHelper.getPagePath(pageId);
// Resolves templates such as:
// {{workspaceId|}} and {{calculationId|123}}
path = route.replace(
/\{\{([^}|]+)\|([^}]*)\}\}/g,
(match, key, defaultValue) => {
const value = Object.hasOwn(params, key)
? params[key]
: defaultValue;
if (
value === undefined ||
value === null ||
value === ''
) {
throw new Error(
`Missing path parameter "${key}" for page "${pageId}".`
);
}
return encodeURIComponent(String(value));
}
);
return wwLib.wwApp.goTo(path, query);
}
return navigateToPage(pageId, parameters, query)
Depending whether code is executed in the editor or in the published app, it will navigate to the specified page with the passed path parameters.