我尝试在angular 2 RC
中实现此路线示例:
/search/[:category/][:subcategory/][:brand/][:page/]?limit=15&sort=price
我该怎么做?我可以使用查询参数来处理所有内容,但URL是"丑陋"。否则,如果我使用查询参数,有一种方法可以重写网址? PHP非常简单,我正在研究角度2:)
我尝试在另一个组件中执行此类操作,但不起作用且name: 'message'
有错误
@Routes([
{path:'/', component: ListMessagesComponent },
{path:'/:id/', component: MessageComponent, name: 'message'},
{path:'/:id/:sort/', component: MessageComponent, name: 'message-sorted'}
])
控制台日志:for / messages / 1 / desc / (这没有任何意义)
Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.
platform-browser.umd.js:971EXCEPTION: Error: Uncaught (in promise): Cannot match any routes. Current segment: '1'. Available routes: ['/', '/:id/', '/:id/:sort/'].
platform-browser.umd.js:962EXCEPTION: Error: Uncaught (in promise): Cannot match any routes. Current segment: '1'. Available routes: ['/', '/:id/', '/:id/:sort/'].BrowserDomAdapter.logError @ platform-browser.umd.js:962BrowserDomAdapter.logGroup @ platform-browser.umd.js:972ExceptionHandler.call @ core.umd.js:3696(anonymous function) @ core.umd.js:8951schedulerFn @ core.umd.js:6007SafeSubscriber.__tryOrUnsub @ Subscriber.ts:240SafeSubscriber.next @ Subscriber.ts:192Subscriber._next @ Subscriber.ts:133Subscriber.next @ Subscriber.ts:93Subject._finalNext @ Subject.ts:154Subject._next @ Subject.ts:144Subject.next @ Subject.ts:90EventEmitter.emit @ core.umd.js:5996onError @ core.umd.js:6227onHandleError @ core.umd.js:6096ZoneDelegate.handleError @ zone.js:327Zone.runGuarded @ zone.js:233_loop_1 @ zone.js:487drainMicroTaskQueue @ zone.js:494ZoneTask.invoke @ zone.js:426
platform-browser.umd.js:962STACKTRACE:BrowserDomAdapter.logError @ platform-browser.umd.js:962ExceptionHandler.call @ core.umd.js:3698(anonymous function) @ core.umd.js:8951schedulerFn @ core.umd.js:6007SafeSubscriber.__tryOrUnsub @ Subscriber.ts:240SafeSubscriber.next @ Subscriber.ts:192Subscriber._next @ Subscriber.ts:133Subscriber.next @ Subscriber.ts:93Subject._finalNext @ Subject.ts:154Subject._next @ Subject.ts:144Subject.next @ Subject.ts:90EventEmitter.emit @ core.umd.js:5996onError @ core.umd.js:6227onHandleError @ core.umd.js:6096ZoneDelegate.handleError @ zone.js:327Zone.runGuarded @ zone.js:233_loop_1 @ zone.js:487drainMicroTaskQueue @ zone.js:494ZoneTask.invoke @ zone.js:426
platform-browser.umd.js:962Error: Uncaught (in promise): Cannot match any routes. Current segment: '1'. Available routes: ['/', '/:id/', '/:id/:sort/'].
at resolvePromise (zone.js:538)
at resolvePromise (zone.js:523)
at zone.js:571
at ZoneDelegate.invokeTask (zone.js:356)
at Object.onInvokeTask (core.umd.js:6066)
at ZoneDelegate.invokeTask (zone.js:355)
at Zone.runTask (zone.js:256)
at drainMicroTaskQueue (zone.js:474)
at XMLHttpRequest.ZoneTask.invoke (zone.js:426)BrowserDomAdapter.logError @ platform-browser.umd.js:962ExceptionHandler.call @ core.umd.js:3699(anonymous function) @ core.umd.js:8951schedulerFn @ core.umd.js:6007SafeSubscriber.__tryOrUnsub @ Subscriber.ts:240SafeSubscriber.next @ Subscriber.ts:192Subscriber._next @ Subscriber.ts:133Subscriber.next @ Subscriber.ts:93Subject._finalNext @ Subject.ts:154Subject._next @ Subject.ts:144Subject.next @ Subject.ts:90EventEmitter.emit @ core.umd.js:5996onError @ core.umd.js:6227onHandleError @ core.umd.js:6096ZoneDelegate.handleError @ zone.js:327Zone.runGuarded @ zone.js:233_loop_1 @ zone.js:487drainMicroTaskQueue @ zone.js:494ZoneTask.invoke @ zone.js:426
zone.js:461 Unhandled Promise rejection: Cannot match any routes. Current segment: '1'. Available routes: ['/', '/:id/', '/:id/:sort/']. ; Zone: angular ; Task: Promise.then ; Value: BaseException {message: "Cannot match any routes. Current segment: '1'. Available routes: ['/', '/:id/', '/:id/:sort/'].", stack: "Error: Cannot match any routes. Current segment: '…st:3000/node_modules/zone.js/dist/zone.js:322:35)"}consoleError @ zone.js:461_loop_1 @ zone.js:490drainMicroTaskQueue @ zone.js:494ZoneTask.invoke @ zone.js:426
zone.js:463 Error: Uncaught (in promise): Cannot match any routes. Current segment: '1'. Available routes: ['/', '/:id/', '/:id/:sort/'].(…)
答案 0 :(得分:0)
新路由器目前要求首先订购更具体的路由,而不是最后订购的特定路由
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target 'myapp' do
pod 'IQKeyboardManagerSwift', '<= 4.0.0'
pod 'JSQMessagesViewController', '<= 7.3.1'
pod 'Firebase'
end
@Routes([
{path:'/:id/:sort/', component: MessageComponent}
{path:'/:id/', component: MessageComponent},
{path:'/', component: ListMessagesComponent },
])
在新路由器中不再存在。
我不确定(仅)支持只有参数不同的路线
name