Hey Everyone! I am trying to follow the tutorial o...
# suitecommerce
b
Hey Everyone! I am trying to follow the tutorial on https://developers.suitecommerce.com/page-navigation-and-redirection.html to Redirect a User Back to their Current Page. The problem I am running into though, is that our SCA sites are single page applications, so as I roam around the website, the url doesn't change to reflect that. I am trying to find what event I can bind to in order to update that, but I am struggling to find it. Is there an easy way to trigger an event when the hash changes? Thanks!
s
Your comment is a little confusing to me. All SCA sites are SPAs and the URL bar is designed to update every time a user navigates to a different page. If it's not doing that then something is fundamentally broken in the site and I'm surprised it even functions.
b
Sorry, the URL in the browser works great. The URL in the login button, that I set following the tutorial doesn't update
How can I rerender _header_profile.tpl_ whenever the URL bar updates
s
Oh I see what you mean.
It certainly is possible to re-render the header instance or just the individual child view, but off the top of my head I don't know the best practice of doing it
You can access the header instance by using getLayout() on the application object, so you could call a render from that. You would then have to bind that to an event.
Will have to think about that
b
I was following your instructions on https://developers.suitecommerce.com/page-navigation-and-redirection.html to redirect a customer after login
But ran into this problem
s
OK, here is what I think is an acceptable solution to this:
Copy code
container.getLayout().on('beforeRender', function () {
    function generateLoginUrl () {
        var login = container.getComponent('Environment').getSiteSetting('touchpoints.login');
        var origin = container.getComponent('Environment').getConfig('currentTouchpoint');
        var hash = Backbone.history.fragment;
        var loginUrl = login + '&origin=' + origin + '&origin_hash=' + hash;

        return loginUrl
    }

    var Layout = container.getComponent('Layout');
    Layout.addToViewContextDefinition('Header.Profile.View', 'loginUrl', 'string', function (context) {
        return generateLoginUrl()
    })

    Backbone.history.on('route', function () {
        container.getLayout().headerViewInstance.render()
    })
})
You're using Backbone to listen to the route changing and then calling render on the header view instance
b
Thanks!