Seeking guidance as a newcomer to routing and Single Page Applications in AngularJS. I am currently facing an issue and would greatly appreciate any assistance in resolving it.
Background
I have a "Products list" page showcasing products in a ng-repeat loop. Upon clicking on a product link, the application navigates to a "Details" page (an extension of the 'Products list' page in SPA) for that specific 'id' through an href call.
<a href="{{id}}/Details" class="button"> Details
In order to route to the 'Details' page, we established an app.config as follows
in Productslist.js
-------
$routeProvider
.when("/:id/Details",{ templateUrl : "../ProductsList/Details" , controller :})
.otherwise({
templateUrl : "/"
});
The current flow works seamlessly, allowing me to open the 'Details' page when I am on the 'Products list' page and click on the 'Details' button for any displayed products.
If relevant, the URL appears like: www.abc.com/list/4/Details, showing the details of product id = 4.
Issue / Desired Outcome
Now, from another third page "X", where the Product-ID is obtained, I aim to directly navigate to the product details page without needing to click the "Details" button on Page A.
Given that the module for this page was initially created in the 'Products list' page, I am passing the 'id' value from page X into ProductList.js and intend to set the URL as such to access the 'Details' page.
if(fromPageX == 'true')
{
var x = id+"/Details";
location.href = x; // bypass waiting on page productsList.html, directly open 'Details' page
}
Essentially, my goal is to trigger the "routing" function from the controller in the .js file rather than via the .html file (on-click).
The browser URL correctly displays: www.abc.com/A/4/Details; however, I encounter a 404 - page not found error since it isn't passing through the routing configuration. I've attempted Window.location.href and other suggestions from various sources, yet I'm unable to successfully load the 'Details' page.
- Is this scenario achievable in AngularJS?
- What could be going wrong in my approach?
Appreciate your help and support in advance!