How to change/set the main view using Yeoman with Angular Fullstack

…衆ロ難τιáo~ 提交于 2019-12-08 13:41:40

in your app.js file located at client\app\app.js, in the angular config add the following:

$stateProvider
  .run(function ($state) {
    $state.go('login');
  });

So it should look like:

.config(function ($stateProvider, $urlRouterProvider, $locationProvider, $httpProvider) {
    $urlRouterProvider
      .otherwise('/');

    $locationProvider.html5Mode(true);
    $httpProvider.interceptors.push('authInterceptor');
    $stateProvider
      .run(function ($state) {
        $state.go('login');
      });
  })

I realize this has been out here for a while and you likely already have a good solution, but I was recently looking at this myself and see a couple options.

One, inside app.js you could add the following code snippet under $urlRouterProvider:

.when('/', '/login')

Making your full method be something like:

.config(function ($stateProvider, $urlRouterProvider, $locationProvider, $httpProvider) {
    $urlRouterProvider
       .when('/', '/login')

    $locationProvider.html5Mode(true);
    $httpProvider.interceptors.push('authInterceptor');
})

This would force anyone going to your base page url directly to login, unless they provide the full route to another page. However, if you intend to still use the main.html, you will then need to go into client/app/main/main.js and change the default route to:

.state('main', {
    url: '/main',
    templateUrl: 'app/main/main.html',
    controller: 'MainCtrl'
 });

So main is reachable by appending /main to the url.

Which brings me to option 2: Go into the main.js file and switch it's url to '/main' and go into login.js and switch it's url to '/'. Then anyone navigating to your base page automatically goes to the login screen but the url is viewed as just your domain without any sub page.

So client/app/main/main.js becomes:

.state('main', {
    url: '/main',
    templateUrl: 'app/main/main.html',
    controller: 'MainCtrl'
 });

And client/app/account/account.js now contains:

.state('login', {
    url: '/',
    templateUrl: 'app/account/login/login.html',
    controller: 'LoginCtrl'
 })
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!