Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

New to CanJS - Page Routing Question

$
0
0
I am attempting to use the pushstate and have the following test code working great. I can click links and history generates nicely with pretty urls. However if i refresh any of the pages or copy and paste a url into the browser other than the default route i get a 404. How can i fix this?

require.config(
{
baseUrl: '/',
paths: {
"jquery": "/js/lib/jquery/dist/jquery",
"can": "/js/lib/canjs/amd/can",
}
});

require([
        'can/route/pushstate',
        'can/control',
        'can/control/route'
], 
function () {
$(document).ready(function(e) {
console.log('jquery and dom are ready');
});
    var Routing = can.Control({}, {
    'init': function() {
        console.log('router init');
    },
    //default router
    'route' : function(){
        console.log('default route');
$('h2').html('Default');
$('title').text('Default');
$('#content').html('<a href="/">Home</a><a href="page1">page1</a><a href="page2">page2</a>');
    },

    'page1 route' : function(){
        console.log('Page 1');
$('h2').html('Page 1');
$('title').text('Page 1');
    },
'page2 route' : function(){
        console.log('Page 2');
$('h2').html('Page 2');
$('title').text('Page 2');
    },


});

    new Routing('body');
    can.route.ready();

});


Viewing all articles
Browse latest Browse all 3491

Trending Articles