So this is what I am trying to accomplish:
'use strict';  var app = angular.module('myModule', ['ngRoute']);  app.config(function($routeProvider) {   $routeProvider     .when('/', {       redirectTo: '/pages'     })     .when('/pages/:pageName', {       templateUrl: 'views/pages/'+pageName+'html',       controller: 'MainController'     }); });   Basically, I want to use the uri to determine which template is used. Currently I get an error that pageName is not defined which I understand. What would be a different way of doing this? Thanks!
templateUrl returned a function instead of a string. To get it to work, all I had to do was pass back in $stateParams like so: $state. current. templateUrl($stateParams) .
Routing allows us to create Single Page Applications. To do this, we use ng-view and ng-template directives, and $routeProvider services. We use $routeProvider to configure the routes. The config() takes a function that takes the $routeProvider as a parameter and the routing configuration goes inside the function.
templateUrl can be a function accepting object of route parameters:
.when('/pages/:pageName', {     templateUrl: function(params) {         return 'views/pages/' + params.pageName + '.html';     },     controller: 'MainController' }); 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With