I configured my RouteInitializer as following:
class AppRouteInitializer implements RouteInitializer {
init(Router router, ViewFactory view) {
router.root
..addRoute(
name: 'root',
path: '/lounge_client_demo/web/lounge_client_demo.html',
mount: (Route route) => route
..addRoute(
name: 'lobby',
path: '#lobby',
enter: view('views/LobbyView.html'))
..addRoute(
name: 'chat',
path: '#chat',
enter: view('views/ChatView.html'))
..addRoute(
name: 'default',
defaultRoute: true,
enter: (_) => router.go('lobby', {'param': ':param'}, startingFrom: route, replace: false))
);
}
}
The URL's to lobby and chat:
http://127.0.0.1:3030/lounge_client_demo/web/lounge_client_demo.html#lobby
http://127.0.0.1:3030/lounge_client_demo/web/lounge_client_demo.html#chat
are working as expected. But, when I submit an URL like:
http://127.0.0.1:3030/lounge_client_demo/web/lounge_client_demo.html
or
http://127.0.0.1:3030/lounge_client_demo/web/lounge_client_demo.html#xxx
the rule in the defaultRoute is producing the following wrong URL:
http://127.0.0.1:3030/lounge_client_demo/web/lounge_client_demo/.html#lobby
Am I assuming something wrong here or is it just a bug?
UPDATE: The logging shows that the dot in the URL is being escaped and might be wrongly transformed into the target URL.
2014-01-29 01:20:18.026: FINEST : route /lounge_client_demo/web/lounge_client_demo.html [Route: null]
2014-01-29 01:20:18.035: FINEST : _processNewRoute /lounge_client_demo/web/lounge_client_demo.html
2014-01-29 01:20:18.047: FINEST : route [Route: root]
2014-01-29 01:20:18.055: FINEST : _processNewRoute
2014-01-29 01:20:18.066: FINEST : go /lounge_client_demo/web/lounge_client_demo\.html#lobby
2014-01-29 01:20:18.075: FINEST : route #lobby [Route: root]
2014-01-29 01:20:18.087: FINEST : _processNewRoute #lobby
2014-01-29 01:20:18.099: FINEST : route [Route: default]
2014-01-29 01:20:18.108: FINEST : route [Route: lobby]
UPDATE: I have copied the lounge_client_demo.html into test.file.with.dots.html and get the following URL rewrite:
http://127.0.0.1:3030/lounge_client_demo/web/test/.file/.with/.dots/.html#lobby
The logging shows that every period is being "escaped" by a backslash:
2014-01-30 01:16:28.246: FINEST : go /lounge_client_demo/web/test\.file\.with\.dots\.html#lobby
Possibly a problem with the period character in the route_hierarchical package?!
You should not be including # in the route paths, so just 'lobby', not '#lobby' -- router is doing that for you. If you want to use the fragment (#...) for routing then you need to include the following in your module:
module.value(NgRoutingUsePushState, NgRoutingUsePushState.value(false));
which tells the router to use window.location.hash instead of window.location.path for routing, as well as to listen to window.onHashChange instead of window.onPopState.
That said, you can either do path matching or fragment matching, but not both. So, you'll also need to remove the 'root' route (for path '/lounge_client_demo/web/lounge_client_demo.html'). Once you switch to fragment matching path becomes irrelevant, only stuff after # is passed to the router.
Your route configuration should look something like this:
class AppRouteInitializer implements RouteInitializer {
init(Router router, ViewFactory view) {
router.root
..addRoute(
name: 'lobby',
path: 'lobby',
enter: view('views/LobbyView.html'))
..addRoute(
name: 'chat',
path: 'chat',
enter: view('views/ChatView.html'))
..addRoute(
name: 'default',
defaultRoute: true,
enter: (_) => router.go('lobby', {'param': ':param'}));
}
}
Related
I have a problem with routing and tx_news in TYPO3 9.5. I have tried all the official examples, but the problem still exists and I can't find out why.
Id' like to have URL like:
...home/news/detail/project-lounge-movetia-2
But I get:
...home/news/detail/project-lounge-movetia-2?tx_news_pi1[day]=11&tx_news_pi1[month]=12&tx_news_pi1[year]=2019&cHash=8fd7057d32ae3e3810b76f0bf4a06e39
The config is standard:
routeEnhancers:
News:
type: Extbase
limitToPages:
- 40
- 54
- 55
extension: News
plugin: Pi1
routes:
- routePath: '/'
_controller: 'News::list'
- routePath: '/page-{page}'
_controller: 'News::list'
_arguments:
page: '#widget_0/currentPage'
- routePath: '/{news-title}'
_controller: 'News::detail'
_arguments:
news-title: news
- routePath: '/{category-name}'
_controller: 'News::list'
_arguments:
category-name: overwriteDemand/categories
- routePath: '/{tag-name}'
_controller: 'News::list'
_arguments:
tag-name: overwriteDemand/tags
defaultController: 'News::list'
defaults:
page: '40'
aspects:
news-title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
page:
type: StaticRangeMapper
start: '1'
end: '100'
category-name:
type: PersistedAliasMapper
tableName: sys_category
routeFieldName: slug
tag-name:
type: PersistedAliasMapper
tableName: tx_news_domain_model_tag
routeFieldName: slug
requirements:
page: '\d+'
The newstitle gets correctly "enhanced", but the rest is still there (hash, id, etc) I have no clue why this happens. I read the manual about routing a lot of times, but I don't get it. :(
It should contain little bit more as showed in their documentation
routeEnhancers:
News:
type: Extbase
limitToPages:
- 104
extension: News
plugin: Pi1
routes:
- routePath: '/'
_controller: 'News::list'
- routePath: '/page-{page}'
_controller: 'News::list'
_arguments:
page: '#widget_0/currentPage'
- routePath: '/{news-title}'
_controller: 'News::detail'
_arguments:
news-title: news
- routePath: '/{category-name}'
_controller: 'News::list'
_arguments:
category-name: overwriteDemand/categories
- routePath: '/{tag-name}'
_controller: 'News::list'
_arguments:
tag-name: overwriteDemand/tags
defaultController: 'News::list'
defaults:
page: '0'
aspects:
news-title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
page:
type: StaticRangeMapper
start: '1'
end: '100'
category-name:
type: PersistedAliasMapper
tableName: sys_category
routeFieldName: slug
tag-name:
type: PersistedAliasMapper
tableName: tx_news_domain_model_tag
routeFieldName: slug
Unwanted params
Actually date params like &tx_news_pi1[day]=20&tx_news_pi1[month]=7 are NOT default ones, which mean that you copied some TS snippet, which includes it or maybe some of your co-workers put it there.
According to News' Humane readable dates documentation search for plugin.tx_news.settings.link.hrDate node in your TypoScript and modify or remove it to get rid date params in single-view links.
Eventually, if you want to keep them, but with human-readable URLs, take a look into the newest documentation of the ext:news which has a sample for proper dates routing with aspects.
I have found the solution. The problem was not the routing, but the raw news URL contained all the additional params {day}{month}{year}. The following SETUP setting turns this off:
plugin.tx_news.settings.link.hrDate = 0
By disabling it, the raw URl generated looks like this:
?tx_news_pi1[action]=detail&tx_news_pi1[controller]=News&tx_news_pi1[news]=486&cHash=
It works now perfectly.
Thanks to biesior for pushing me to the solution!
I am having issues setting up my Angular project with .NET MVC 5.0. I am not sure what's wrong with the below code. When I run the application, unexpectedly to me, app shows the template set in app-component.ts and not login
const appRoutes: Routes = [
{ path: '', redirectTo: 'login', pathMatch:'full' },
{ path: 'login', component: LoginComponent },
// otherwise redirect to home
{ path: '**', redirectTo: 'login' }
];
To test out the things, and ignore MVC controller/view routing for a second, I also tried creating html file inside in my login folder,
#Component({
moduleId: module.id,
templateUrl: 'login-component.html' -- This was initially /Public/Login -Path to the MVC controller
})
Project is shared on a github project here
https://github.com/GAK-MPRO/AngularMVCStarter/tree/Master/A2Rnd
My question is.. what do I need to do to route my views using MVC routing with views rendered by calling controllers.
Change the order in which your routes are defined. The default routes should always be at the end of the route list:
const appRoutes: Routes = [
{ path: 'login', component: LoginComponent },
{ path: '', redirectTo: 'login', pathMatch:'full' },
// otherwise redirect to home
{ path: '**', redirectTo: 'login', pathMatch:'full' }
];
I just looked at your code on git hub. The bootstrap module is trying to bootstrap appcomponent and the appcomponent does not have an router-outlet tag. Edit the template in the app.component.ts file to include
<router-outlet></router-outlet>
and it should show you both app component and login components html content.
import { Component } from '#angular/core';
#Component({
selector: 'my-app',
template: '<h1>Hello {{name}}</h1><br/><router-outlet></router-outlet>',
})
export class AppComponent { name = 'Angular'; }
I have defined a route as per the below but I am getting some errors. Below is the code outlining what is happening
namespace :shopping do
resources :merchants, only: [:index, :show] do
Which I was hoping I would be able to use = link_to shopping_merchant_path(merchant)
But this is giving me the following error
No route matches {:action=>"show", :controller=>"shopping/merchants", :id=>nil, :locale=>#<Merchant id: 1, name: "52e9689bc89a", featured: false>} missing required keys: [:id]
rake routes output
Pauls-Air% rake routes | grep shopping_merchant
shopping_merchant_products GET (/:locale)/shopping/merchants/:merchant_id/products(.:format) shopping/products#index {:locale=>/en/}
shopping_merchant_product GET (/:locale)/shopping/merchants/:merchant_id/products/:id(.:format) shopping/products#show {:locale=>/en/}
shopping_merchants GET (/:locale)/shopping/merchants(.:format) shopping/merchants#index {:locale=>/en/}
shopping_merchant GET (/:locale)/shopping/merchants/:id(.:format) shopping/merchants#show {:locale=>/en/}
As onikron suggested you need to pass parameter to your route
= link_to shopping_merchant_path(#merchant)
I think you are trying something like
= link_to shopping_merchant_path(locale: #merchant)
:locale=>#< Merchant id: 1, name: "52e9689bc89a", featured: false>
No need of :locale in link_to
I want to config prefix for url.File route.php is something like this
Route::group(['prefix' => 'speech', 'as' => 'speech'], function()
{
Route::resource('user', 'UserController', ['as' => 'speech.user']);
});
And in file blade, linkRoute is something like this
{{ Html::linkRoute('speech.user.index') }}
That's code will show error : Route [speech.user.index] not defined.
What can I do?
Try this
{{ url('/speech/user/index') }}
I have this route:
# :chwid => Camera Hardware ID - :mid => Machine ID - :fs => FormatString
get '/videocams/video/:chwid/:mid/:fs' => "videocams#get_videocams_id", :constraints => { :chwid => /[^\/]+/, :mid => /[^\/]+/, :fs => /[^\/]+/ }
But when I call the route, my first parameter :chwid contains the character # and ?:
(#device:pnp:\?\root#image#0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global)
and an error is called:
Started GET "/videocams/video/#device:pnp:%5C%5C?%5Croot"
ActionController::RoutingError (No route matches [GET] "videocams/video/#device:pnp:%5C%5C":
What might be triggering this error and how can I fix it?
URL-escape characters that have meaning in URLs lie # and ?.