Aharanov-Bohm Effect Gradient of Line Integral In Griffiths' Quantum Mechanics 2nd edition section 10.2.3 the phase
$$g(\mathbf{r}) = \frac{q}{\hbar}\int_{O}^{\mathbf{r}}\mathbf{A}(\mathbf{r}')\cdot d\mathbf{r}'$$
is defined. It is noted that this integral is only defined if $\nabla\times\mathbf{A} = 0$ throughout the region and the region is simply connected (noted in the 3rd edition). The gradient of this function is then found to be
$$\nabla g = \frac{q}{\hbar}\mathbf{A}.$$
If my understanding is correct this is due to the Fundamental Theorem of Line Integrals along with the above comments implying $\mathbf{A}$ is conservative. Hence,
$$\mathbf{A} = \nabla a$$
so that
$$\begin{split}\nabla g &= \nabla\left(\frac{q}{\hbar}\int_{O}^{\mathbf{r}}\mathbf{A}(\mathbf{r}')\cdot d\mathbf{r}'\right)\\ &= \frac{q}{\hbar}\nabla\left(a(\mathbf{r})-a(O)\right)\\ &= \nabla a(\mathbf{r})\\ &= \mathbf{A}.\end{split}$$
Assuming this is correct we come to my question. Griffiths introduces the Aharanov-Bohm Effect for a particle in a box, with $\mathbf{r}$ denoting its position and $\mathbf{R}$ that of the centre of the box. He then defines
$$g = \frac{q}{\hbar}\int_{\mathbf{R}}^{\mathbf{r}}\mathbf{A}(\mathbf{r}')\cdot d\mathbf{r}'$$
for this system. He then calculates
$$\nabla_{\mathbf{R}}\left(e^{ig}\right) = -i\frac{q}{\hbar}\mathbf{A}(\mathbf{R})e^{ig}.$$
I don't understand how this was found since the particle's position changes as $\mathbf{R}$ is moved so should also contribute to the derivative. Also, I feel that the conditions for $\mathbf{A}$ to be a conservative field aren't satisfied in this case. The region enclosed by the solenoid having non-zero curl.
Would someone be able to clarify these points for me?
 A: I think $\mathbf{r}$ is just an arbitrary position in space where the particle could be for the integral in the definition of $g$. So it doesn't depend on $\mathbf{R}$ in $g$. It is the potential $V$ used in other parts of the setup which confines the particle's position $\mathbf{r}$.
We can treat the space outside the solenoid as two simply connected parts: $$H_1 := \{r>a,\,0\leq\phi\leq \pi,\,-\infty\leq z\leq \infty\}\quad\text{ and }\quad H_2 := \{r>a,\,-\pi\leq\phi\leq 0,\,-\infty\leq z\leq \infty\}$$
specified in cylindrical coordinates, where in both $H_1$ and $H_2$ we have that $\mathbf{A}$ is curl free. So by the simply connectedness $\mathbf{A}=\nabla\varphi_1$ on $H_1$ for a potential field $\varphi_1$ on $H_1$ and $\mathbf{A}=\nabla\varphi_2$ on $H_2$ for a potential field $\varphi_2$ on $H_2$.
It follows by the same theorem that $\varphi_1(\mathbf{R}) = g(\mathbf{R})$ for $\mathbf{R}$ in $H_1$ and similarly for $\varphi_2$. To be completely precise there should really be a $g_1$ defined for $\mathbf{R}$ in $H_1$ and a $g_2$ defined for $\mathbf{R}$ in $H_1$. This is since $g$ is not well defined due to the non-simply connectedness of the space outside the solenoid.
Hence by the fundamental theorem of calculus for line integrals
$$\nabla_{\mathbf{R}}g(\mathbf{R}) = -i\frac{q}{\hbar}\mathbf{A}(\mathbf{R})$$
on both $H_1$ and $H_2$. Thus also everywhere outside the solenoid, which gives the result.
