Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8622829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:08:46+00:00 2026-06-12T07:08:46+00:00

Say I have 2 HTML pages, foo.html and bar.html . Inside foo.html : <a

  • 0

Say I have 2 HTML pages, foo.html and bar.html.

Inside foo.html:

<a href="/foo.html" class="selected">Open Foo</a>
<a href="/bar.html">Open Bar</a>
<!-- shared content -->
<div id="content">Nested HTML specific to Foo</div>
<!-- shared content -->

Inside bar.html:

<a href="/foo.html">Open Foo</a>
<a href="/bar.html" class="selected">Open Bar</a>
<!-- shared content -->
<div id="content">Nested HTML specific to Bar</div>
<!-- shared content -->

As expected, when I click a link in either page, it will open the corresponding page. Now, I want to “AngularJSify” this so that clicking a link will only update div#content. I tried this:

$routeProvider
.when('/foo.html', {templateUrl:'/foo.html?onlyContent=true'})
.when('/bar.html', {templateUrl:'/bar.html?onlyContent=true'})
<div id="content" ng-view>Nested HTML specific to Foo (or Bar, depending which page you're in)</div>

But opening foo.html will also load foo.html?onlyContent=true which is unnecessary because foo.html already has the content!

You might be asking, “Why not use empty div#content?” Because I want to (1) Reduce loading extra file, and (2) Make the content available even if JS is disabled.

In Backbone.js I can use:

Backbone.history.start({pushState:true, silent:true});

Which basically means, “If the page is already loaded, don’t invoke the route again.” How do I achieve that in AngularJS?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:08:48+00:00Added an answer on June 12, 2026 at 7:08 am

    Inside foo.html:

    <a href="/foo.html" class="selected">Open Foo</a>
    <a href="/bar.html">Open Bar</a>
    <div id="defaultTemplate">Nested HTML specific to Foo</div> <!-- note this -->
    <div id="content" ng-view></div>
    

    Inside bar.html:

    <a href="/foo.html">Open Foo</a>
    <a href="/bar.html" class="selected">Open Bar</a>
    <div id="defaultTemplate">Nested HTML specific to Bar</div> <!-- note this -->
    <div id="content" ng-view></div>
    

    In JavaScript:

    function routing(path, controller, template) {
        var route = {templateUrl:'/templates/' + path, controller:controller};
    
        if (path === window.location.pathname) {
            var defaultTemplate = $('#defaultTemplate');
    
            route = {template:defaultTemplate.html(), controller:controller};
            defaultTemplate.remove();
        }
    
        $routeProvider.when(path, route);
    }
    

    Essentially means, “if the route you’re opening is the same with the path in address bar, use template from current page instead”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have this sample: page = <html><body><h1 class='foo'></h1><p class='foo'>hello people<a href='http://'>hello world</a></p></body></html>
lets say i have two pages links.html & contents.php ... first page contains only
Lets say there are two pages with two different html elements which have the
I have page(lets say https://example.com/dir1/tidy.html ), that embeds an iframe that hosts content from
If I have say 20 HTML pages and I want to extract out the
Well, say I have a number of html pages in my web. The case
Let's say I have this HTML markup on an aspx page: <div id =
Let's say that I have two html pages that are identically designed, but have
Lets say i have this javascript code in an html pages <script type=text/javascript> $(document).ready(function(){
I have 5 pages - for ease lets say: one.html two.html three.html four.html five.html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.