Skip to content

Commit

Permalink
closes #172
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Oct 20, 2023
1 parent 91fbc53 commit a1fab0a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/router-hoc.riot
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
getBase(context) {
const baseAttr = getAttribute(BASE_ATTRIBUTE_NAME)
return baseAttr ? this.el.getAttribute(BASE_ATTRIBUTE_NAME) || baseAttr.evaluate(context) : '/'
return baseAttr ? baseAttr.evaluate(context) : this.el.getAttribute(BASE_ATTRIBUTE_NAME) || '/'
},
setBase(context) {
setBase(props ? props.base : this.getBase(context))
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import route, {
toPath,
toRegexp,
toURL,
configure,
defaults,
} from 'rawth'
import Route from './components/route-hoc.riot'
import Router from './components/router-hoc.riot'
Expand All @@ -13,6 +15,8 @@ import initDomListeners from './dom.js'
import setBase from './set-base.js'

export {
defaults,
configure,
route,
createURLStreamPipe,
match,
Expand Down
12 changes: 11 additions & 1 deletion test/components.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { base, sleep } from './util.js'
import HistoryRouterApp from './components/history-router-app.riot'
import NestedUpdates from './components/nested-updates.riot'
import RecursiveUpdatesBugRouter from './components/recursive-updates-bug-router.riot'
import StaticBasePath from './components/static-base-path.riot'
import { component } from 'riot'
import { expect } from 'chai'
import { router } from '../src/index.js'
import { router, defaults } from '../src/index.js'

describe('components', function () {
beforeEach(async function () {
Expand Down Expand Up @@ -73,4 +74,13 @@ describe('components', function () {

comp.unmount()
})

it('Static base path attributes are supported (bug 172) ', async function () {
const el = document.createElement('div')
const comp = component(StaticBasePath)(el)

expect(defaults.base).to.be.equal('https://riot.rocks/app')

comp.unmount()
})
})
24 changes: 24 additions & 0 deletions test/components/static-base-path.riot
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<static-base-path>
<router base="/app">
<a href="/home">
Home
</a>
<route path="(.*)">
<p>{state.message}</p>
</route>
</router>

<script>
import { Router, Route } from '../../src/index.js'
export default {
components: {
Router,
Route,
},
state: {
message: 'hello',
}
}
</script>
</static-base-path>

0 comments on commit a1fab0a

Please sign in to comment.