How can I develop a SPA with jQuery? I did with AngularJS with the following code, however I am having difficulties to migrate to it definitively and decided to keep with jQuery so as not to be late.
var myapp = angular.module('myapp', []);
myapp.config(function($routeProvider) {
$routeProvider
.when('/:acess', {
templateUrl : 'sources/default.html',
controller : 'myapp-controll'
})
.otherwise({ redirectTo: '/welcome' });
});
myapp.controller('myapp-controll', function($scope, $routeParams) {
$scope.templateUrl = './g_c.php?a='+$routeParams.acess;
});
This code loaded my pages without leaving the original page, using #
Explaining better:
Let's pretend that there is a file like this:
./pages/ (pasta) ----
index.html (este) |
--/> home.html
|
--/> produtos.html
When you click on Pagina inicial
it has to load into the "content" div all the contents of the requested file, ie it would have to just get the home
and pull it from inside the pages
folder by throwing all the content in the div and loading it completely.
But what? if I want to share the link, will I have to teach the user how to check it? Which buttons to click? This would cause the site to lose many users and access, so the answer is no!
Or if I provided the http://meusite/#/produtos/
link to someone, when accessing it, you have to load the contents of the page produtos
into the "content" div automatically, without having to click anything.
<div id="inicio"><a href="#/home/">Pagina inicial</a> | <a href="#/produtos/">Produtos</a> | </div>
<div id="conteudo">Oi, eu sou a pagina inicial</div>