Resolve feature for UI routes fails to function upon refreshing the page

My app utilizes UI Route for view routing.

When accessing /berlinerliste/, a function is triggered to display an array of objects.

If one of these objects is clicked, the view changes to /berlinerliste/{id}/ and shows the details of that specific object.

The issue arises when the individual object with the URL /berlinerliste/{id}/ is reloaded, resulting in a page without data.

This is how the service is structured:

.factory('SearchService', ['$http', function($http) {

  var service = {

    flatexhibitors : [],
    datafairs : [],
    flatexhibitorsuni : [],
    datafairsuni : [],

    getAllExhibitors : function () { //initial call to fetch all items on page load
        var searchindex = 'XX';
        var url = '../getexhibitors.php';
        var config = {
            params: {
                search: searchindex
            },
            cache:true
        };
        $http.get(url, config).then(function (data) {
          service.datafairs = data.data.rows;
          for (var i in service.datafairs) {
            service.flatexhibitors.push(service.datafairs[i].doc);
          };
          return service.flatexhibitors;
        });
    },

    getAllPeople: function() { //call to reload data and filter it 
      var searchindex = 'XX';
      var url = '../getexhibitors.php';
      var config = {
          params: {
              search: searchindex
          },
          cache:true
      };
      return $http.get(url, config).then(function (resp) {
        service.datafairsuni = resp.data.rows;
        for (var i in service.datafairs) {
          service.flatexhibitorsuni.push(service.datafairs[i].doc);
        };
        return service.flatexhibitorsuni;
        console.log(service.flatexhibitorsuni);
      });
    },

    findExh : function(id){
      function personMatchesParam(exhibitor) {
        return exhibitor.slug === id;
        console.log(exhibitor.slug);
      }
      return service.getAllPeople().then(function (data) {
        return data.find(personMatchesParam)
      });

    }
  }

  service.getAllExhibitors();

  return service;

}])

This is the configuration of my views:

.config(function($stateProvider) {

  var berlinerState = {
    name: 'berliner',
    url: '/berlinerliste/',
    views: {
      'header': {   
        templateUrl: 'header.htm'   
      },
      'main':{    
        templateUrl: 'bl2017.htm'    
      }
    }
  }

  var exhibitorState = { 
    name: 'exhibitor', 
    url: '/berlinerliste/{id}', 
    views: {
      'header': {   
        templateUrl: 'header.htm'  
      },
      'main':{    
        templateUrl: 'exhibitor.htm'    
      }
    },
    resolve: {
      exhibitor: function(SearchService, $stateParams) {
        return SearchService.findExh($stateParams.id);
      }
    }
  }

  $stateProvider.state(berlinerState);
  $stateProvider.state(exhibitorState);
})

Despite the issue with the reload not functioning properly at /berlinerliste/{id}/, it also impacts the speed by making redundant HTTP calls and filtering processes. Any tips on resolving this?

  • Making duplicate HTTP calls (unnecessary if not reloading the page)
  • Filtering items based on ID
  • Correctly displaying the results from /berlinerliste/ but showing nothing upon reload

I believe ideally, the redundant HTTP call and the resolve process should only occur during a page reload, not when navigating from the parent URL. What am I missing?

You can view the live version here

UPDATE

Check out the Plunkr example from the UI Router developers where they successfully implement what I'm attempting. It works for them but not for me.

Answer №1

When you refresh the page, it's like starting your application from scratch. In a single-page application, this means losing all data because everything will be reloaded. You'll need to retrieve the data from the server again or store it in the browser's local storage. One solution is to extract the id from the URL and update your API call to the specific child route instead of the parent route like this: #!/berlinerliste/{id}.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Managing additional hash characters in a route: Tips for handling excess hash symbols in AngularJS 1.5 with the new/component router

We're currently working on developing an application using Angular 1.5 along with the new component router features. Our team has encountered a unique situation and we are curious if there are any potential solutions available. The Key Players Iden ...

Vue.js Conditional Templates

I am attempting to implement VueJs conditional rendering using handlebars in vueJs 2.0 as outlined in their official documentation, but eslint is throwing an error: - avoid using JavaScript keyword as property name: "if" in expression {{#if ok}} - avoid us ...

Having issues with Next.js server-side rendering when integrating API functionality

"Not building properly" means that the project is not fully completing the build process. I've developed a simple blog project with dynamic SSR that pulls data from the Notion-API to generate static blog pages. Everything functions correctly ...

Ways to customize the border color on a Card component using React Material UI

Is there a way to change the border color of a Card component in React Material UI? I attempted using the style property with borderColor: "red" but it did not work. Any suggestions on how to achieve this? ...

Error: Material-UI X is unable to locate the data grid context

Utilizing the Data Grid Pro feature from Material-UI in my React application. I attempted to craft a personalized toolbar for the DataGridPro component by incorporating the GridToolbarColumnsButton, GridToolbarFilterButton, GridToolbarDensitySelector, and ...

When the update button is clicked, the textfield is hidden; it reappears upon refreshing the page

Our marketplace multi-vendor site on Magento allows sellers to list their products for sale. The frontend displays the price using the following code: Phtml <input onFocus="showPriceCancel('<?php echo $products->getId(); ?>');" clas ...

Determine the position and quantity of elements in jQuery by comparing their IDs with the current page or element

Looking to retrieve the n (zero based) position of an element by matching the page and element ID... Let's use an example (Assume the current page ID is 488); <ul id="work-grid"> <li id="item-486" class="work-item"><!--/content--& ...

AngularJS: Understanding the difference between ng-show and using display:none

I recently encountered a scenario where I needed to hide an HTML element by default using CSS. Here's how I did it: HTML: <div class="box"> </div> CSS: .box { display: none; } However, I wanted to be able to show and hide the elem ...

AngularJs Application Encountering Issues with Loading/Installing Google Maps API

I'm attempting to integrate Google Maps into my Angularjs app following the instructions provided here: http://angular-ui.github.io/angular-google-maps/#!/use After meticulously following all the steps, I encountered the following error: The script ...

Switching the default z-index for child elements within an HTML container

According to the specification, elements are typically drawn "in tree order" for in-flow, non-positioned elements of similar block level or float status and identical z-index. This means that elements declared last in the HTML markup appear on top. But wha ...

Discover how to shallow test for the presence of a wrapped component using Jest and Enzyme

Currently, I am in the process of testing a component that dynamically renders another wrapped component based on certain conditions. My testing tools include enzyme and jest, with the root component being rendered using the shallow() method. The main chal ...

Exploring the capabilities of CasperJS through double clicking

I'm currently working on creating a bot using CasperJS. The main goal is for the bot to send trade offers by offering an item, but I'm facing difficulties in figuring out how to click on the item. I attempted to use Resurrectio, however, it' ...

When attempting to pass data to another page by clicking on a row, the result is that the data appears to be empty

I have been using the MUI-Datatable component, which is able to navigate to the next page. However, when I try to view the data on the History page, nothing appears. How can I resolve this issue? Data transfer to another page: Even though I can see the d ...

Looking for a method to incorporate an onclick function into a column for renderCell within the MUI Datagrid. Any suggestions?

I'm currently developing a react application and utilizing the MUI Datagrid to present some data. I have incorporated a rendercell to insert an edit icon which should trigger a pop-up modal when clicked. Below is the column setup. export const specifi ...

The combination of React and Redux with the utilization of combined reducers

Hey there, I'm currently utilizing thunks to retrieve data from my backend, but I'm a bit uncertain on how to implement it in my combined reducer. Here are my types: export const FETCH_SUCCESS = 'FETCH_SUCCESS'; export const FETCH_FAI ...

Vows.js: Utilizing data from parent topics in nested topics

Is there a way to access the return value of an outer topic from within a test in an inner topic? To clarify, consider this example: "build.css" : { topic : function(file) { fs.readFile(fixtures + "/public/build.css", "utf8", this.callback); }, ...

Transmitting multiple file attachments to a PHP file through AJAX

In my form, I have the following HTML code: <input type="file" id="attachments" name="attachments" multiple> I've already implemented a JavaScript function that handles form submission using AJAX, but it doesn't handle uploaded files. Wi ...

Is the Await keyword failing to properly pause execution until the promise has been fulfilled?

I'm currently working on manipulating a variable within an async function, and I've noticed that the variable is being returned before the completion of the data.map function below. Even though I have the await keyword in place to pause the code ...

What could be the reason for data-id coming back as undefined?

I'm having trouble figuring out why the code below isn't working for me. The console is showing 'undefined' for data-id. href='#detailsModal' class='btn btn-info btn-xs' data-toggle='modal' data-id='x ...

Having difficulty drawing an arrow connecting one mesh object to the surface of another mesh object

When attempting to draw an arrow from one mesh object to another, I encountered some issues. Directly using the positions of the objects as arguments in the Arrow Helper resulted in the arrow going inside the object due to the position representing the cen ...