简体   繁体   English

角路由将路径返回到html而不是html

[英]Angular Routing is returning the path to html instead of the html

It's almost set up, except ui-view is loading the path to my html file instead of the html itself. 它几乎已设置好,除了ui-view正在将路径加载到我的html文件而不是html本身。

import angular from 'angular';
import angularMeteor from 'angular-meteor';
import template from './main.html';
import uiRouter from 'angular-ui-router';

import About from '../pages/about/about';

export default angular.module('main', [
  angularMeteor,
  uiRouter,
  About.name
])
  .component('main', {
    templateUrl: 'imports/main/main.html',
    controller: MainCtrl
  })
  .config(config);

function config($locationProvider, $urlRouterProvider) {
  'ngInject';

  $locationProvider.html5Mode(true);

  $urlRouterProvider.otherwise('/');
}

Here's the about page javascript 这是关于页面的javascript

class About {}

const name = 'about';

export default angular.module(name, [angularMeteor, uiRouter])
.component(name, {
  template,
  controllerAs: name,
  controller: About
})
.config(config);

function config($stateProvider) {
  'ngInject';

  $stateProvider
  .state('about', {
    url: '/about',
    template: '<about></about>'
  });
}

So it will say /imports/pages/about/about.html instead of what's actually in the html file. 因此它将显示/imports/pages/about/about.html而不是html文件中的实际内容。

I think you're not pointing to the file the right way. 我认为您没有以正确的方式指向文件。

Try to change the following: 尝试更改以下内容:

$stateProvider
.state('about', {
url: '/about',
template: '<about></about>'
});

into

$stateProvider
.state('about', {
url: '/about',
template: require('/imports/pages/about/about.html')
});

Let me know if this works. 让我知道这个是否奏效。

将模板更改为templateUrl

templateUrl: 'imports/pages/about/about.html',

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM