oraclejet icon indicating copy to clipboard operation
oraclejet copied to clipboard

oj.Router conflicts

Open stanislav-web opened this issue 6 years ago • 2 comments

Hello! I need the ability to use the router in the application as a "wild card. I have the router settings in a separate module and i wouldn't like to divide structure for child routes in each of its viewModel. In my application, it is necessary to configure all the routes from one module, but at the moment I'm a little stumped.

This example does not work, because the rule 'list' always overrides the template, but only if i remove it then the 'list/order/{orderId}' route will work.

http://url.com/list/order/1111 -> load viewModels/list.js instead of viewModels/list/order.js . Why ?

I will be grateful any helps

@ Oracle JET 4.2.0

// router.js
define([], () => {

    return {
		
		'list': {
                    id: 'list',
                    label: 'Order list',
                    value: 'list'
               }
		'list/order/{orderId}': {
                    id: 'list/order',
                    label: 'View Order', // title postfix
                    value: 'list/order' // viewModel location
               }
       }
})
// application.js
define(['ojs/ojcore', 'router'], (oj, router) => {

        /**
         * ApplicationViewModel root view model
         */
        class ApplicationViewModel {
		
		constructor() {
                    oj.Router.defaults['baseUrl'] = document.getElementsByTagName('base')[0].getAttribute('href')
                    oj.Router.defaults['urlAdapter'] = new oj.Router.urlPathAdapter()
                    this.router = oj.Router.rootInstance.configure(router)
	        }
	}
}

I would like to create the possibility of a hierarchy without building child routes from modules.

stanislav-web avatar Mar 11 '18 20:03 stanislav-web

The paths configured for your router states cannot contain forward slashes unless you're using them to distinguish the single state Id from the parameters. The state Id is always the first segment, so in your second configuration "list" is the stateId, but "order" is ignored. So in fact, you have to configurations for "list" which won't work. You could instead do something like 'list-order/{orderId}'

itlgit avatar Apr 26 '19 14:04 itlgit

Thank you, i did it already , but this routes patterns aren't so user friendly

stanislav-web avatar Jun 25 '19 13:06 stanislav-web