Redirecting from one page to another

add-on
jira-plugin
jira-cloud
atlassian-connect

#1

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?


#2

Depending on the destination page, you may be able to use the JavaScript API method AP.navigator.go().


#3

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


#4

@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"
         }
      ]
   }
}

#5

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?


#6

@hariprasath, use customData described in Navigator~context, e.g. AP.navigator.go('addonModule', { addonKey: 'some-addon', moduleKey: 'page2', customData: {some-parameter: 'some-value'}});.


#7

@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=""/>

#8

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.


#9

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?