I would like to use url parameters for routing in angularjs
I have an anguar app with 2 views : editView and mainView
Given a url that looks like this: 'httx://myapp/?param1=x&...&editmode=1&...'
-> will get me to the /editMode Path
What would be a good way to do so?
do i need html5 mode?
There is nothing i can do about the url - i am forced to use the editmode parameter
$routeProvider.when('/', {
controller: function($routeParams, $location) {
if($routeParams.editmode == '1') {
$location.path('editMode') ...
Overview. The $routeParams service allows you to retrieve the current set of route parameters. Requires the ngRoute module to be installed. The route parameters are a combination of $location 's search() and path() . The path parameters are extracted when the $route path is matched.
To access the route parameters, we use route. snapshot , which is the ActivatedRouteSnapshot that contains information about the active route at that particular moment in time. The URL that matches the route provides the productId . Angular uses the productId to display the details for each unique product.
Routing in AngularJS is used when the user wants to navigate to different pages in an application but still wants it to be a single page application. AngularJS routes enable the user to create different URLs for different content in an application.
Generate an application with routing enabledlink The following command uses the Angular CLI to generate a basic Angular application with an application routing module, called AppRoutingModule , which is an NgModule where you can configure your routes.
I found out that "resolve:" instead of "controller:" was what i needed. If anyone is interested in changing routes via params, this is the way to go: https://github.com/angular/angular.js/issues/1838#issuecomment-13994168
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