Limited work has been done on causal mediation analysis in the complex situation in which both the mediator and final outcome are measured repeatedly. Some recent approaches, including one using a continuous time model, are limited in being parametric and sensitive to model assumptions. To provide a more flexible and robust causal mediation analysis for longitudinal data, we propose a semiparametric continuous time model approach using a joint linear spline model for the mediator and the final outcome, when both are measured repeatedly. The component models use penalized splines, implemented in a mixed effect model framework, for both the mean and individual response functions. The joint model is fit in conjunction with an extended mediation formula and sequential ignorability assumption to estimate natural direct and indirect effects, both overall and as a function of time. The new method is applied to data from a cohort study to assess attention as a mediator of the effect of prenatal drug exposure on externalizing behavior in adolescence.