I don't think you need to use Velocity here and above. There are JavaScript APIs to create document references and URLs. For instance:

    new XWiki.Document(pageName, spaceName).getURL('get', queryString)