How can I handle back button on pages with templates?

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How can I handle back button on pages with templates?



I am working on a site using angularjs. I divide the page into two section: menu and content.



for example



this a page: /mainpage


<div>
<div id="menu">
<div ng-click="setTemplate('firstPage.html')">Page 1</div>
<div ng-click="setTemplate('secondPage.html')">Page 2</div>
<div ng-click="setTemplate('thirdPage.html')">Page 3</div>
</div>
<div id="content" ng-template="template">
</div>
</div>



controller:


$scope.template = 'firstPage.html';
$scope.setTemplate = function(value)
$scope.template = value;



So after click on Page 1 Then Page 2 Then Page 3. So when i click on the back button, it load the last page / but not /mainpage with the right template. How would i handle the back button to not go back to previous page and go to previous template if there was a template change?



Thanks.




2 Answers
2



You should look at https://github.com/angular-ui/ui-router. You could build the functionality yourself, but ui-router is pretty much where you will end up.



The problem is you have nothing for it to default to. When you click back, it's just loading /mainpage, but it has no template to load in. Usually you use a $routeprovider for this:


$routeProvider
.when('/',

controller: 'yourControllerName.js',
templateUrl:'mainpage.html'
)
.otherwise(

redirectTo : '/'
);






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

2ljUBPuxZq fV3fKe7aRSRI0sQ3 tJpaEdes,3gX9UWtd0M3LTO8itfMYJPDh,09x2U839HN2ZSnP3tC033
6oOK,TTCrEiq9z4l7L4W,tW9ALuu,1oXp12JoUKGVRm

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3