How to redirect from one page to another in connect add-on. Have loaded a page using url in atlassian connect.json as below,
"modules": {
"generalPages": [
{
"key": "connectaddon",
"location": "system.top.navigation.bar",
"name": {
"value": "Page1"
},
"url": "/Page1",
"conditions": [{
"condition": "user_is_logged_in"
}]
}
]
}
Now, the page ‘Page1’ gets loaded which contains a anchor tag. On clicking the tag it should redirect to another page. How can I perform this?
Depending on the destination page, you may be able to use the JavaScript API method AP.navigator.go()
.
Hello @epehrson,
I have tried AP.navigator.go() as below,
AP.navigator.go('addonModule', { addonKey: {{addonKey}}, moduleKey: 'Addon-key2'});
Cannot get value for {{addonKey}} as it throws undefined error. How can I access that key using meta tag or any other option is there?
Currently, I have two pages in atlassian-connect.json as follows,
"modules": {
"generalPages": [
{
"key": "Addon-key1",
"location": "system.top.navigation.bar",
"name": {
"value": "Page1"
},
"url": "/Page1",
"conditions": [{
"condition": "user_is_logged_in"
}]
},
{
"key": "Addon-key2",
"location": "none",
"name": {
"value": "Page2"
},
"url": "/Page2?value={somevalue}",
"conditions": [{
"condition": "user_is_logged_in"
}]
}
]
}
When I click on the button in ‘page 1’, then ‘Page 2’ must be loaded along with few parameters in url. How can I solve this using AP.navigator.go()?
Cheers,
Hari Prasath P
@hariprasath, given the following app descriptor (with some required fields omitted), to navigate from page1 to page2, you could call AP.navigator.go('addonModule', { addonKey: 'some-addon', moduleKey: 'page2'});
.
{
"key": "some-addon",
"modules":{
"generalPages":[
{
"key": "page1"
},
{
"key": "page2"
}
]
}
}
2 Likes
Hello @epehrson,
Thanks for your solution. I am able to redirect using ap.navigator.go.
Now, I need to redirect within same page using different id passing as parameter in url. How can I perform this?
@hariprasath, use customData
described in Navigator~context, e.g. AP.navigator.go('addonModule', { addonKey: 'some-addon', moduleKey: 'page2', customData: {some-parameter: 'some-value'}});
.
2 Likes
@epehrson, Thanks a lot. I can redirect now using AP.navigator.go. Can I use this code within anchor tag? As I need to redirect to different pages with various anchor tags. Also, when I use this navigator, the redirected page does not contain the JWT token in meta tag.
<meta name="token" content=""/>
1 Like
Can I use this code within anchor tag? As I need to redirect to different pages with various anchor tags.
For us to load the iframe with a URL fragment? That isn’t supported currently, but you could raise a feature request.
Also, when I use this navigator, the redirected page does not contain the JWT token in meta tag.
This I don’t really understand. What meta tag? Are you talking about atlassian-connect-express? That meta tag is rendered by your add-on server, given that there is an authenticated user.
Actually, I am validating each request from client side using addon.authenticate(). It works fine for the home page as I can get the jwt token from atlassian-connect. But, in the redirected page I am unable to get the jwt from meta tag.
Here is the link where I had raised a question. Can you please suggest me a solution for that?
Hi @epehrson,
Is there any option to access the addonKey, moduleKey dynamically as below
AP.navigator.go('addonModule', { addonKey: {{addon.key}}, moduleKey: {{module.key}}, customData: {id: taskId, domid: domainId}});
from page params or any other instead of hard-coding the key values within quotes?
@hariprasath that depends on your add-on. atlassian-connect-express does seem to include {{addonKey}}
as a render context variable. If you want to include the module key, you will need to add it to the render context yourself. See the Express documentation for that.