I want to use dynamic routing in builder.ai using RunEngine, How can I fix that?
To implement dynamic routing (e.g., Profile/:id
), you can follow this method:
1. Use the predefined NavigationScreenNameMessage
to pass the value in the URL. :
handleRecruiterNavigation = (recruiterId: number) => { const message: Message = new Message(getName(MessageEnum.NavigationMessage)); message.addData(getName(MessageEnum.NavigationTargetMessage), 'Profile'); message.addData(getName(MessageEnum.NavigationPropsMessage), this.props); message.addData(getName(MessageEnum.NavigationScreenNameMessage), recruiterId); this.send(message); }
2. Ensure that you update the path in the app.js
file to handle the dynamic route.
RecruiterProfile1:{ component:RecruiterProfile1, path:"/Profile/:navigationBarTitleText", private: true, roles: ["recruiter", "candidate"] },
3. In the RecruiterProfile1.controller.tsx
file, you can retrieve the value from the URL.
const recruiterId = this.props.navigation.getParam("navigationBarTitleText")
1 correction is here, key should match the pathname
Profile:{ component:RecruiterProfile1, path:"/Profile/:navigationBarTitleText", private: true, roles: ["recruiter", "candidate"] },
path:”/Profile/:navigationBarTitleText”,
`:navigationBarTitleText` do not change this text to custom name. it will not work.
Here is a solution for implementing routing with query parameters.
To use routing with query parameters, we can integrate NavigationPayLoadMessage
to set and retrieve the parameters. However, it’s important to note that using this method will result in the parameters being removed when the page is refreshed.
For passing the query in navigation :
navigateToJob = (jobId: number) => { const message: Message = new Message(getName(MessageEnum.NavigationMessage)); message.addData(getName(MessageEnum.NavigationTargetMessage), `Catalogue`); message.addData(getName(MessageEnum.NavigationPropsMessage), this.props); const payloadMessage: Message = new Message(getName(MessageEnum.NavigationPayLoadMessage)) payloadMessage.addData(getName(MessageEnum.NavigationPayLoadMessage), { query: jobId }) message.addData(getName(MessageEnum.NavigationRaiseMessage), payloadMessage); this.send(message); }
To get the query
constructor(props: Props) { this.subScribedMessages = [ getName(MessageEnum.NavigationPayLoadMessage) ] } async receive(from: string, message: Message) { if (getName(MessageEnum.NavigationPayLoadMessage) === message.id) { const data = message.getData( getName(MessageEnum.NavigationPayLoadMessage) ); } }