Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set root location for AngularJS router?

Tags:

angularjs

I would like to start navigation from http://mysite.com/hello/world, not from site root.

e.g.

$routeProvider
  .when('/myurl', {
    templateUrl: 'mytmpl.html',
    controller: 'MyCtrl'
  });

should react when my url is http://mysite.com/hello/world/myurl

How could I do that?

like image 343
ValeriiVasin Avatar asked Jun 26 '13 12:06

ValeriiVasin


People also ask

How do I set up a route in AngularJS?

To make your applications ready for routing, you must include the AngularJS Route module: Then you must add the ngRoute as a dependency in the application module: Now your application has access to the route module, which provides the $routeProvider. Use the $routeProvider to configure different routes in your application:

What is the angular router?

It is a "batteries-included" framework that comes with many powerful libraries and modules baked in so that you can start building your app quickly. One of the features that Angular includes out-of-the-box is the Angular Router. In this guide, you will learn how to use the Angular Router— specifically the forRoot and forChild static methods.

What is the--Routing Parameter in the angular CLI?

Note: The Angular CLI does not let you use the --routing parameter until version 8.1. The forRoot static method is the method that configures the root routing module for your app. When you call RouterModule.forRoot (routes), you are asking Angular to instantiate an instance of the Router class globally.

What is approutingmodule forroot in angular?

When you call RouterModule.forRoot (routes), you are asking Angular to instantiate an instance of the Router class globally. Just like Angular creates a new base AppModule to import all of your feature modules, it also provides the AppRoutingModule to import all of your child routes.


1 Answers

Add base tag to the main HTML file that is being served when user navigates to http://example.com/hello/world:

<base href="/hello/world/" />

More info can be found at Developer Guide / Using $location

like image 138
Stewie Avatar answered Dec 15 '22 01:12

Stewie