[英]Angular routing issue when accessing url based on id
My end goal is to allow users to access products when clicking on the item itself. 我的最终目标是允许用户在单击商品本身时访问产品。 So for each product item rendered in main.html the url is something like...
因此,对于main.html中呈现的每个产品项,URL都类似于...
<a href="/products/{{ product.id }}">{{ product.title }}</a>
for example: right now when inside localhost:8000/products/4/
the itemDetails.html page shows but with a ton of 404 errors and 例如:现在,当在
localhost:8000/products/4/
,itemDetails.html页面显示,但出现大量404错误,并且
Error: $injector:nomod Module Unavailable Module 'productFind' is not available
错误:$ injector:nomod模块不可用模块'productFind'不可用
my items.route.js looks like this: 我的items.route.js看起来像这样:
(function () {
'use strict';
angular
.module('items')
.config(routerConfig);
function routerConfig($stateProvider) {
$stateProvider
.state('itemDetails', {
url: '/products/:id',
templateUrl: 'items/itemDetails.html',
controller: 'ItemDetailsController',
controllerAs: 'itemDetails'
})
}
})();
and my index.html renders 和我的index.html呈现
<div ng-view></div>
the index.module.js index.module.js
import { config } from './index.config';
import { routerConfig } from './index.route';
import { runBlock } from './index.run';
import { MainController } from './main/main.controller';
import '../app/components/items/items.module.js';
import { ItemDetailsController } from '../app/components/items/items.controller';
import { GithubContributorService } from '../app/components/githubContributor/githubContributor.service';
import { WebDevTecService } from '../app/components/webDevTec/webDevTec.service';
import { NavbarDirective } from '../app/components/navbar/navbar.directive';
import { MalarkeyDirective } from '../app/components/malarkey/malarkey.directive';
angular.module('productFind', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ngMessages', 'ngAria', 'ngRoute', 'toastr', 'items'])
.constant('malarkey', malarkey)
.constant('moment', moment)
.config(config)
.config(routerConfig)
.run(runBlock)
.service('githubContributor', GithubContributorService)
.service('webDevTec', WebDevTecService)
.controller('MainController', MainController)
.controller('ItemDetailsController', ItemDetailsController)
.directive('acmeNavbar', NavbarDirective)
.directive('acmeMalarkey', MalarkeyDirective);
My file structure looks like so... 我的文件结构看起来像这样...
productFind
...
src
app
components
items
itemDetails.html
items.controller.js
items.module.js
items.route.js
itemsDataService.js
main
main.controller.js
main.html
index.module.js
index.route.js
I'm assuming this is a routing issue so my question is: what am I doing wrong to be receiving this error message when I try to access the item/product details : localhost:8000/products/4/? 我假设这是一个路由问题,所以我的问题是:当我尝试访问商品/产品详细信息时,收到此错误消息我做错了什么:localhost:8000 / products / 4 /?
You are using ngRoute
and ng-view
with with $stateProvider
.. $stateProvider
is from UI-Router. 您正在将
ngRoute
和ng-view
与$stateProvider
一起使用。 $stateProvider
来自UI-Router。 Get UI-Router and use ui.router
and ui-view
instead. 获取UI-Router并改用
ui.router
和ui-view
。 This alone should fix your problem. 仅此一项就可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.